如何使用存储过程进行插入查询 [英] how to use stored procedure for insert query
本文介绍了如何使用存储过程进行插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想使用存储过程。我写了程序执行成功。
但是我没有得到如何传递.cs文件中的值。
我的代码是如下: -
Hi
I want to use stored procedure. I written procedure its execute successfully.
but i didn't get how to pass the value in .cs file.
My code is as follows:-
SqlConnection con = dt.SqlCon;
dt.OpenCon();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_master_applicant";
cmd.parameters.addwithvalue("@company_name", drdwncompany.selectedvalue.tostring());
cmd.parameters.addwithvalue("@email_address", txtemail_id.text);
cmd.parameters.addwithvalue("@first_name", txtfirstname.text);
cmd.parameters.addwithvalue("@last_name", txtlast_name.text);
cmd.parameters.addwithvalue("@password", txtpassword.text);
cmd.parameters.addwithvalue("@confirm_password", txtre_password.text);
cmd.parameters.addwithvalue("@phone_no", txt_phnno.text);
cmd.parameters.addwithvalue("@mobile_no", txtmobile.text);
cmd.parameters.addwithvalue("@roles", drdwrole.selectedvalue.tostring());
cmd.parameters.addwithvalue("@li_admin", ckadmin.checked ? "1" : "0");
cmd.parameters.addwithvalue("@li_application_form", ckemployee_registration.checked ? "1" : "0");
推荐答案
请参阅此链接:如何在ASP.net中使用C#与Sql Server一起使用存储过程
请参阅此链接您的想法: 在SQL Server中创建表和存储过程,并使用C#从ASP.NET连接它[ ^ ]
http:// msdn .microsoft.com / zh-CN / library / yy6y35y8%28v = vs.71%29.aspx [ ^ ]
Refer this link you got Idea : Create Table and Stored Procedure in SQL Server and connect it from ASP.NET using C# [^]
http://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.71%29.aspx[^]
using (SqlConnection con = new SqlConnection(dt.SqlCon)) {
using (SqlCommand cmd = new SqlCommand("sp_master_applicant")) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.parameters.addwithvalue("@company_name",drdwncompany.selectedvalue.tostring());
cmd.parameters.addwithvalue("@email_address", txtemail_id.text);
cmd.parameters.addwithvalue("@first_name", txtfirstname.text);
cmd.parameters.addwithvalue("@last_name", txtlast_name.text);
cmd.parameters.addwithvalue("@password", txtpassword.text);
cmd.parameters.addwithvalue("@confirm_password", txtre_password.text);
cmd.parameters.addwithvalue("@phone_no", txt_phnno.text);
cmd.parameters.addwithvalue("@mobile_no", txtmobile.text);
cmd.parameters.addwithvalue("@roles", drdwrole.selectedvalue.tostring());
cmd.parameters.addwithvalue("@li_admin", ckadmin.checked ? "1" : "0");
cmd.parameters.addwithvalue("@li_application_form", ckemployee_registration.checked ? "1" : "0");
con.Open();
cmd.ExecuteNonQuery();
}
}
这篇关于如何使用存储过程进行插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文