Tuesday, February 08, 2005 3:08 AM
ExecuteRow is a new method in .net that will return 1 record from the query. Here is a sample from .Net Beta 1:
ConnectionStringSettingsCollection cssc = ConfigurationSettings.ConnectionStrings;
string connectionstring = cssc["Main"].ConnectionString;
string sql = "select * from Customers where CustomerId = 'ANTON' "; // Using Northwind Database
SqlConnection conn = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlRecord record = cmd.ExecuteRow();
Response.Write(record["ContactName"].ToString());
conn.Close();
NOTE: queries without the WHERE condition will return the first record.