You must Sign In to post a response.
  • Category: ASP.NET

    Update data with two tables

    hi everyone,
    how i can update data in two tables a time.
    my data like,
    id Qution
    1 1234?
    2 4321?

    table 2
    optioid id option
    1 1 10
    2 1 8
    3 1 7
    4 1 6

    like that . i want catch the option id and qutioid in

    in my gridview like

    Qution option1 option2 option3 option4
    1234? 10 8 7 6

    in table how i can catch the both qutionid and optionid.

    Thank you i hope all understanding my qution
  • #763576

    As per my understand the post you want to insert your gridview result set into 2 different tables, right?

    If your requirement is like that then refer below sample code this will help you to complete your task.

    protected void btnInsert(object sender, EventArgs e)
    foreach(GridViewRow row in gv.Rows)
    int qstId=Convert.ToInt32((row.FindControl("lblqstId") as Label).Text);
    //get all the controls data like above and pass as parameter while insert into your desired tables

    like above you can get the gridview cell values and insert those into different tables while passing those as a input parameters.

    If you still having any concerns then please let us know.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763578
    hi naveensanagasetti sir,
    thank you response,
    can you please first do the sql query.
    how i can update the data in two tables at a time as per my requirements.
    thank you

  • #763581
    Hello Sadiq,

    You have the option in using SP.

    1. Insert the first table record and get the scope identity as output parameter

    CREATE PROCEDURE [dbo].[p_AddFirstTable]
    @Name varchar(75),
    @Id bigint OUT
    INSERT INTO [FirstTable](

    If you send @Id as output parameter, you can read this value from your C# code as follows.
    string zResultL = TheCommandL.Parameters["@Id"].Value.ToString();

    Insert the second table using the first table identity value.

    By Nathan
    Direction is important than speed

  • #763587
    Hi Sadiq,

    To insert data into 2 tables at a time using same parameters, then first you need to create appropriate procedure for the same.

    create procedure proc_name
    --input parameters
    --insert data into first table
    insert into table1(field1,field2,field3....)

    --insert data into second table
    insert into table2(field1,field2,field3....)

    You can do in the above way to insert records into different tables in single approach.

    If you still have any concerns please let us know.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763602
    thank you for responding,
    please again read my question.
    i want update in two tables.
    Thank you

  • #763863
    To do that i think you need gridview. First bind question in main gridview then fetch all option related to the question id in the next templated column.
    If you are unable to do something properly for the first time, call it Version 1.0!

    Thanks & Regards,

  • Sign In to post your comments