Hi,
i want to add new record into a SQL Server 2000 database from the controls of form using ADO.NET.Can someone help me how i can write the code for this ?????
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
paparaoPosted Jul 20, 2007, 2:50 AM
1) u should create table name like (student) in database or u can create from front end
itself and create some fields like sno and sname ok..........
2) u should take fields like student number, student name and u take button name
like ADD or INSERT ok................
3)double click ADD or INSERT button and then
4)go to the coding part and type following statement in namespaces
using System.Data.SqlClient;
5) Button1_click
{
try
{
sqlconnection con= new sqlconnection
(userid=..;password=................;server=............;database=............. ");
sqlcommand cmd=new sqlcommand();
con.open();
cmd.commandtext="insert into student values
("+textbox1.text+",'"+textbox2.text+"')";
cmd.connection=con;
cmd.ExecuteNonQuery();
con.close();
Response.Write("Records Are Insertd");
}
catch(SqlException e)
{
Response.write(E.Message());
}
}//Button1
Jan MontanoPosted Jun 25, 2007, 10:45 PM
Here's a link to get you started:
This example constructs an insert query.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1738271&SiteID=1