How do i check database table through datatable and extract information of
another column of database table?
I was trying to check whether there is any rows having username and friend
username in database table. If any then I have to take the friendship
status in a string and will return that string.
Here is the code:
string query = "Select * from tblfriend where username = '" + username +
"'and friend = '" + friendname + "'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
rows = dt.Rows.Count;
if (rows > 0)
{
friendship = reader["friendshipstatus"].ToString();
}
But it gives a error message:
Invalid Call to call MetData when reader is closed.
Can you guys please give a hint?
No comments:
Post a Comment