【发布时间】:2020-08-24 01:33:21
【问题描述】:
我正在使用 DataSet 检索特定的列值。
这是我的代码:
public DataSet GetRedirectURL(string emailId)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(@"Connection_String_Here"))
{
con.Open();
SqlCommand sqlComm = new SqlCommand("usp_Login", con)
{
CommandType = CommandType.StoredProcedure
};
sqlComm.Parameters.AddWithValue("@EmailId", emailId);
SqlDataAdapter da = new SqlDataAdapter
{
SelectCommand = sqlComm
};
da.Fill(ds);
}
return ds;
}
我也使用 DataTable 代替它,但结果相同。 我检查了我的存储过程,当我传递参数时它显示数据。所以,SP没有错。但是 Table 没有显示任何数据,并且始终为空,如下所示:
我错过了什么?任何帮助将不胜感激。
【问题讨论】:
-
您是否尝试过执行您的
SqlCommand本身? -
你没有在任何地方打开你的连接。在传递给命令对象之前打开它
-
@VishalPawar 即使打开连接,DataSet 结果也是空的。
-
关注这可能会有所帮助dotnetperls.com/sqldataadapter
-
很高兴我的回答帮助了你@noobprogrammer !!
标签: c# stored-procedures dataset sqlconnection dataadapter