insert in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dipalichavan82
    New Member
    • Feb 2008
    • 41

    insert in database

    i m using asp.net vs2005.i have gridview on page.it displays datatable values.i have insert button on page.i want to insert data in textbox into database.i m using disconnected archi.


    protected void BtnInsert_Click (object sender, EventArgs e)
    {
    SqlDataAdapter adap= new SqlDataAdapter( "select * from info", con2);
    adap.MissingSch emaAction = MissingSchemaAc tion.AddWithKey ;
    ds= new DataSet();
    adap.Fill(ds,"t ");
    DataRow drow = ds.Tables["t"].NewRow();
    drow[0] = TextBox1.Text;
    drow[1] = TextBox2.Text;
    drow[2] = TextBox3.Text;
    drow[3] = TextBox4.Text;
    ds.Tables["t"].Rows.Add(drow) ;
    adap.Update(ds, "t");
    }


    i m getting error on this:
    Update requires a valid InsertCommand when passed DataRow collection with new rows.

    can anyone tell me code to insert data in database using dataadpter,plz tell
    thnx in advance
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Your insert statement looks remarkably like a select query. Suggest you learn the basics, there are many online tutorials - try google.

    MODERATOR

    Comment

    Working...