sql查询 返回单行单列 ExecuteScalar

 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是查询多行多列的语句,返回也只是返回第一行第一列的结果
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页