2

How can I manually add row/insert into DB with a gridview control?

I need to perform some calculations on the user input first before sending the data to the INSERT sql query.

There is a gridview.Insert() method but it does not take any parameters.

How can I pass it my parameters, which come from textboxes, dropdownlists, etc and then run the sql query?

1
  • Add it to the end(or beginning) of the datatable with dt.Add(...) before binding Commented Mar 13, 2013 at 12:11

1 Answer 1

1

Try to add it in datatable before binding it:

DataRow dr = dt.NewRow();
// set dr fields here
dt.Rows.Add(dr);
Sign up to request clarification or add additional context in comments.

4 Comments

Will that persist in the Database also? Or just in the gridview?
@sd_dracula Just in the gridview.
I need to update the DB also. How can I run a sql insert with my custom parameters?
the way you insert data in DB depends on approach you choose to communicate with it. it can be done using ado.net, linq etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.