I have a question: is it possible to select data from a table in string (without using ToString method) rows?
Without using SqlDataReader and with good performance.
For example read all table and put data to List of string type.1 element=1row
SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=;Password=");
conn.Open();
SqlCommand command = new SqlCommand("Select id from [table1] where name=@zip", conn);
command.Parameters.AddWithValue("@zip","india");
// don't use reader
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
//List<string> = String.Format(row properties...)
}
}
Sorry for bad explanation
SqlDataReaderentirely isn't possible, as it's the common ground for everything in .NET that reads data from SQL Server, but there are certainly plenty of libraries that abstract away from it.ExecuteScalar, but then you'd only get the value of the first column in the first row...SqlDataReader, either directly or indirectly -- in fact, libraries typically benchmark against reading from a rawSqlDataReaderprecisely for this reason, because you can't get any faster (unless you want to implement the protocol from scratch). You can have SQL Server 2017 concatenate strings for you (STRING_AGG) but in earlier versions string concatenation is a much more difficult affair, so that's not really worth it. To optimize concatenation in .NET, useStringBuilder.