Hello everybody!
I'm doing my project about ASP.NET but i don't know how to Insert Data into Database.
Example:
First name: xxxxxxx
Last name: xxxxxxx

Button(<<<)

i want to know how the code working when i click the Button the data first name and last name will go to Database. I'm using SQL database.
Thanks for helping me.

Recommended Answers

All 4 Replies

hi you need to write the connectionstring first which is used to establish a connection between your database and application.

create a db with table name as table_details and fields as fname, lname with varchar type.

Let us take two textboxes with id text_first and text_last.
in button_click event you need to write the following code.

button_click()
{
          sqlConnection con= new sqlconnection("//your db path");
          sqldataAdapter da=new sqldataAdapter("select * from table_details",con);
            DataSet ds=new DataSet();
            da.fill(ds,"table_details");
            dataRow dr;
            SqlCommandbuilder cmd=new sqlcommandbuilder(da);
            dr = ds.Tables["Table_details"].NewRow();
            daInsert.Fill(ds, "Table_Details");

            dr["fname"] = text_first.Text;      
            dr["lname"] = text_last.Text;
            ds.Tables["Table_Details"].Rows.Add(dr);
            da.Update(ds, "Table_Details");
 


}

let me know whether u understand or not?

thanks a lot. I will try rite now.
^^

If your problem is solved please mark it as solved.....

how do we insert data record from front end to back end. am using visual studio as front and toad as back end

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.