Hi, i am using ASP.NET.I want to insert command in asp.net using c#.How can i do?? thanx

Drag a textbox, a button and a SqlDataSource control on the page
Create connection in sqldatasource control. If you dont know how, then follow these steps-:
Near the top-right corner of SqlDataSource control, there is a very small box containing a black symbol '>', click on that.
{
Then click on Configure DataSource.
Click on New connection.
type the server name and database name (and username and password also if required)
click OK
click next,next.
select the table and click on *.
click Finish.
}
Now, on the button click event, type the following command-:
SqlDataSource1.InsertCommand = "insert into table1(column1) values('" + TextBox1.Text + "')";
SqlDataSource1.Insert();
Now, run the page
type something in textbox and click on button, it will insert the value in the database. OK.

hi

first create a connection to database like
sqlconnection con=new sqlconnection("//type here your connection string");

than
on button click event

con.open();
string qry="insert into tablename(id,name)values('"+textbox1.text+"','"+textbox2.text+"')";
sqlcommand cmd=new sqlcommand(qry,con);
cmd.executenonquery();
con.close()


may be this can help you
thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.