string connectionStr = "Server = DESKTOP-IDK01B1\\SQLEXPRESS2014; DataBase = StudentManageDB; Uid = sa; Pwd =sa";
SqlConnection conn = new SqlConnection(connectionStr);
conn.Open();
string commandText = "select StudentName from Students where StudentId = 10007";
SqlCommand command = new SqlCommand(commandText, conn);
object name = command.ExecuteScalar();
Console.WriteLine(name.ToString());
conn.Close();
即使sql語句,即commandText是查詢多行多列的語句,返回也只是返回第一行第一列的結果
sql查詢 返回單行單列 ExecuteScalar
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.