我正在从MSVS中的DataTableAdapters转换到在MS SQL Server中创建存储过程。ASP.NET C#&存储过程
这是我到目前为止。
protected void Submit_Click(object sender, EventArgs e)
{
var conString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("getAdministrators", con))
{
cmd.Parameters.Add("@userName", SqlDbType.VarChar).Value = userNameTB.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = passwordTB.Text;
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
}
}
}
}
我想抓住所有的行/列,并将它们存储在一个DataSet,并使用任何我希望在我的意愿返回的值。我错过了什么来完成这一点。或者如果有人有一篇文章可以提供帮助?
我更新了代码以使用using
。
我觉得代码慢慢变有...
注意:你应该养成使用'using'的东西像'SqlCommand','SqlConnection'等 – 2010-11-18 03:10:59
definetely的习惯。 “迟开,早关”。也 - 你确定这些字段是'VarChar'而不是'NVarChar'? – RPM1984 2010-11-18 03:13:38
在On_Click的开头,我在那里抛出一个使用?任何代码片段或文章? – balexander 2010-11-18 03:15:55