将值从查询表存储到数据库
问题描述:
我正在我的asp.net C#网站创建一个查询表单。使用sql server
i想要将我表单中输入的值存储到数据库中....
任何人都可以帮我这个...
请帮帮我
I am creating a Enquiry form in my asp.net C# website..Using sql server
i want to stored the values enterd in my form to database....
can anyone help me about this...
please help me out
答
首先你在数据库中创建表..
然后使用sql查询将值插入表中..
first you create table in database..
then use sql query to insert values in to the table..
首先你必须创建sql表和必要的sps 。
这里附上一个简单的例子。
Hi,
First you have to create sql tables and needful sps.
here iam attaching a simple example.
Create procedure insert
(@ColumnValue1,@ColumnValue2,@ColumnValue3)
{
insert into tablename (Column1,Column2,Column3)
values(@ColumnValue1,@ColumnValue2,@ColumnValue3)
}
.net part--创建一个向db插入值的方法,并从提交按钮单击调用此方法,或者在按钮单击内写入完整代码。
.net part-- create a method for inserting values to db and call this method from the submit button click or you cam writethe full code inside the button click.
SqlConnection con=new sqlconnection("give ur connection string here");
sqlcommand cmd=new sqlcommand();
con.open();
cmd=new sqlcommand("insert",con);
cmd.commandtype=commandtype.storedprocedure;
cmd.parameters.addwithvalue("@ColumnValue1",txtbox1.text);
cmd.parameters.addwithvalue("@ColumnValue2",txtbox2.text);
cmd.parameters.addwithvalue("@ColumnValue3",txtbox3.text);
cmd.ExecuteNonQuery();
con.close();
希望这可以帮助您获得基本想法。
Hope this will help you to get a basic idea.