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

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

不良信息举报

sql查询 返回单行单列 ExecuteScalar

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭