locked
Advice on using Data Table to insert data into SQL. RRS feed

  • Question

  • User2015884762 posted
    Hi, I have got a grid view made up of 15 rows, each of these rows of data contain about 10 columns. Each cell has 1 label and 12 hidden fields. I would need to send the cell's 13 fields(1 label and 12 hidden fields) information to the database. The thing is the cell's for each row goes into separate tables into the database. For example, cells in row1 has to be inserted into SQL table 1, cells in row2 has to be inserted into SQL table 2 and henceforth. What would be the best approach, I actually created a data table to store each cells 15 fields information and trying to use stored procedure to insert it into the database. Is this the right approach, appreciate any suggestion on how I can do it.
    Saturday, April 6, 2019 12:04 PM

Answers

  • User839733648 posted

    Hi callykalpana,

    callykalpana

    I actually created a data table to store each cells 15 fields information and trying to use stored procedure to insert it into the database. Is this the right approach,

    Yes, you could use stored procedure.

    In my opinion, I suggest that you could just use different SQL statement to insert the data to the datebase you want.

    string testvalue = (gridview1.FindControl("yourcontrolid") as Label).Text;  
    string query = "insert into table_name values(" +testvalue+ ")";  

    Reference: https://www.c-sharpcorner.com/blogs/insert-data-into-database-from-gridview-in-asp-net1

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 8, 2019 9:46 AM