日期:2014-05-18 浏览次数:21171 次
string queryString ="select count(*) as stuNum from student"; string connectionString = "server='(local)';database='mytable';uid='sa';pwd='sa'"; using (SqlConnection connection = new SqlConnection( connectionString)) { SqlCommand command = new SqlCommand( queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { int zh = 0; zh = Convert.ToInt32(reader["stuNum"]); //强制数据转换 } } finally { // Always call Close when done reading. reader.Close(); }