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

问题描述:

亲爱的所有人,



使用存储过程和asp.net在数据库表中插入值这意味着:



i创建了2个网页,其中一个页面包含:姓名,电子邮件,密码



第2页包含:教育,年份



这里这两个网页的名称,电子邮件,密码,教育,年份





这些插入单表这个是否有可能请回复什么或任何示例

Dear All,

insert values in database table using stored procedure and asp.net this means:

i created 2 web pages here one page contain: name, email, password

2nd page contain: education, year

here these two web pages of name, email, password, education, year


these insert single table this is possible or not please reply what about or any examples

表示您想使用两个网页在单个表中插入值。如果这意味着您必须为两个页面调用一个存储的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