c# ado.net里面,executescalar()能不能返回datarow和datacolumn?

[复制链接]
查看11 | 回复2 | 2007-10-20 08:38:44 | 显示全部楼层 |阅读模式
ado.net里面,executescalar()能不能返回datarow和datacolumn??
我下面这样写,对不对??
C# code
public class DBOperator
{
private static string connectionText=......;
public static Object SqlExecuteScalar(string sqlText)
{

Object o;
SqlConnection conn = new SqlConnection(connectionText);
SqlCommand cmd = new SqlCommand(sqlText, conn);
conn.Open();
o = cmd.ExecuteScalar();
conn.Close();
return o;
}
string sqlText1="select * from student where ID='10'";
DataRow dr=DBOperator.SqlExecuteScalar(sqlText1);
string sqlText2=“select ID from student where sex='男'";
DataColumn dc=DBOperator.SqlExecuteScalar(sqlText2);
}
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
不能,这个方法只返回单个值。
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
使用ExecuteReader 方法,或者干脆使用SqlDataAdapter的Fill方法将需要的内容一次性全部读入内存。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行