English 中文(简体)
ASP. NET C# & Stored Procedures
原标题:ASP.NET C# & Stored Procedures

我正在从MSVS的数据表Adapters过渡到在MS服务器上建立储存程序。

这是我迄今为止所做的。

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);
                }
            }
        }
    }

我想 gr掉所有各行/栏目,将其储存在数据表中,并利用我的意愿归还的价值观,以达到我的愿望。 我没有做到这一点。 或者某人是否有可帮助的条款?

我更新了该守则,以使用<代码>。

我认为,该守则正在慢慢慢地付诸实施。

最佳回答

这一氮工艺:

    public static DataSet GetAll(int id)
    {
        using (SqlConnection con = new SqlConnection(Database.ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("sp_ContactGetAll", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    DataSet dsData = new DataSet();
                    da.Fill(dsData);
                    return dsData;
                }
            }
        }
    }
问题回答

I may be wrong, but I would expect the following to work:

using(var reader = cmd.ExecuteReader()) {
  ds.Tables[0].Load(reader);
}

(假定你想要填满零表)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签