Tuesday, 13 August 2013

Retrieving value from sql ExecuteScalar()

Retrieving value from sql ExecuteScalar()

I have the following:
String sql = "SELECT * FROM Temp WHERE Temp.collection = '" +
Program.collection + "'";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);
Program.defaultCollection = (String)cmd.ExecuteScalar();
And I want to get the second column after executing the statement. I know
it will return only one row with two columns
I have read online that I will have to read each row of the result, is
there any other way?
http://www.isaveplus.com

No comments:

Post a Comment