如何使用存储过程编码插入和插入更新(.cs)...我已经编写了insert的代码,这里我还要为更新生成这段代码... [英] how to use stored procedure coding for both insert & update in (.cs)... I have written the code for insert , here I have to make this code for update also…
本文介绍了如何使用存储过程编码插入和插入更新(.cs)...我已经编写了insert的代码,这里我还要为更新生成这段代码...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用存储过程编码在单个函数中的代码隐藏(.cs)文件中插入和更新...我已经编写了插入代码,这里我还要在代码隐藏文件中使这个代码更新...
how to use stored procedure coding for both insert and update in code behind(.cs) file in single function... I have written the code for insert , here I have to make this code for update also in code behind file…
create proc sp_userinformation
(
@username varchar(20),
@password varchar(20),
@firstname varchar(20),
@lastname varchar(20),
@email varchar(20),
@phoneno varchar(20),
@location varchar(15),
@created_by varchar(20),
@ERROR char(500) output),
@indicator char(1)-----U-update and I--Insert
as
if @indicator='I'
begin
insert into userinformation(username,password,firstname,lastname,email,phoneno,location,created_by)values (@username,@password,@firstname,@lastname,@email,@phoneno,@location,@created_by)
set @ERROR='Sucessfully Inserted'
end
If @indicator='U'
begin
update userinformation set
username=@username,password=@password,firstname=@firstname, lastname =@lastname, ,location=@location,created_by=@created_by where email=@email or phoneno=@phoneno
set @ERROR='Sucessfully Updated'
end
protected void btnsubmit_Click(object sender, EventArgs e)
{
string UserName = txtuser.Text;
string Password = txtpwd.Text;
string ConfirmPassword = txtcnmpwd.Text;
string FirstName = txtfname.Text;
string LastName = txtlname.Text;
string Email = txtEmail.Text;
string Phoneno = txtphone.Text;
string Location = txtlocation.Text;
string Created_By = txtuser.Text;
int count = 0;
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=sample;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", UserName);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@FirstName", FirstName);
cmd.Parameters.AddWithValue("@LastName", LastName);
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@PhoneNo", Phoneno);
cmd.Parameters.AddWithValue("@Location", Location);
cmd.Parameters.AddWithValue("@Created_By", Created_By);
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
count = cmd.ExecuteNonQuery();
message = (string) cmd.Parameters["@ERROR"].Value;
con.Close();
Page.RegisterStartupScript("UserMsg", "<Script language="'javascript'">alert('" + "The Values are inserted Successfully " + "');</script>")
lblErrorMsg.Text = message;
}
如何在代码隐藏文件(.cs)中使用此存储过程....
我已编写插入代码,这里如何使这个代码更新也... ...
How to use this stored procedure in codebehind file(.cs)….
I have written the code for insert , here how to make this code for update also…
推荐答案
你检查我的插入和你的更新,但也必须传递你的指标变量的值。 cs.U可以在idicator varible CACH并相应乌尔语句将被执行。
在btnsubmit_Click以下代码
u r checking for i for insert and u for update but have to pass value for ur indicator variable also from .cs.U can cach in idicator varible and accordingly ur statement will executed.
add in btnsubmit_Click following code
cmd.Parameters.AddWithValue("@indicator", "I");
插入
for insert
cmd.Parameters.AddWithValue("@indicator", "U");
for update
for update
这篇关于如何使用存储过程编码插入和插入更新(.cs)...我已经编写了insert的代码,这里我还要为更新生成这段代码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文