且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用存储过程和asp.net在数据库表中插入值?

更新时间:2023-01-22 12:06:32

表示您想使用两个网页在单个表中插入值。如果这意味着您必须为两个页面调用一个存储的Proceder。以下是示例链接



在ASP.NET中使用存储过程插入数据 [ ^ ]
Means you want to insert values in single table using two web pages. IF like that means you have to call one stored Proceder for both two pages. Below is example link

Insert Data Using Stored Procedure in ASP.NET[^]


将此代码添加到您的网页中两个,类似添加网页1 c锐码。你会得到结果。



String ConnString = ConfigurationManager.ConnectionStrings [conString]。ConnectionString;

SqlConnection con = new SqlConnection(ConnString);

SqlCommand cmd = new SqlCommand();

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText =AddUser;

cmd.Parameters.Add(@ Education,SqlDbType.VarChar).Value = Textbox1.Text.Trim();

cmd.Parameters.Add(@ Job_Type,SqlDbType.VarChar).Value = Textbox2.Text.Trim();



cmd.Connection = con;

尝试

{

con.Open();

cmd.ExecuteNonQuery();

lblMessage.Text =记录插入成功;

}

catch(exception ex)

{

throw ex;

}

终于

{

con.Close();

con.Dispose();

}





为理解目的写两个存储过程,否则你会感到困惑。



i我正在写网页2的程序。你写的类似两个页面。

创建程序AddUser



@Location varchar(100),

@Job_type varchar(100)



as

开始



插入用户值(@ Location,@ Job_type)

end。
Add this code into your web page two, similar add web page1 c sharp code. you will get result.

String ConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "AddUser";
cmd.Parameters.Add("@Education",SqlDbType.VarChar).Value = Textbox1.Text.Trim();
cmd.Parameters.Add("@Job_Type", SqlDbType.VarChar).Value = Textbox2.Text.Trim();

cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
lblMessage.Text = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}


Write two stored procedure for understanding purpose, otherwise you will confused.

i am writing procedure for web page 2. you write similar two page1.
create procedure AddUser
(
@Location varchar(100),
@Job_type varchar(100)
)
as
begin

insert into user values(@Location,@Job_type)
end.


第一个网页插入和同一个表的第二页更新
first web page insertion and second page updation of same table