Saving multiple rows of gridview into database

May 17, 2013
Reaction score
Hi there, i have a gridview which populated via selected item on my drop down list which I don't have any problem with that. My problem is I am trying to save multiple rows on my gridview into my database, for example I have added 3 items on my gridview which looks like this:

Id | Name
111 | Jack
222 | Nicole
333 | John

Now, I want all that under column Id which is 111, 222 and 333 will be save on my database once I click Save button I am trying the code below but it gives me an error saying " does not contain a definition for 'Values' and no extension method 'Values' accepting a first argument of type..." :

SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
        SqlCommand cmdd = new SqlCommand("Insert into profile (Id, profile_id)VALUES(@id, @profile_id", con);
        foreach (GridViewRow row in GridView1.Rows)
            cmdd.Parameters.Add("@id", SqlDbType.Char, 20, "Id").Values = row.Cells["Id"].Value;

        cmdd.CommandType = System.Data.CommandType.Text;
        cmdd.Parameters.AddWithValue("@profile_id", txtID.Text);

My table should be look like this once I am able to save multiple rows from my gridview into my database:

auto_id | Id | profile_id
1 |111 | 101
2 |222 | 101
3 |333 | 101

what am I missing? please help. Im using with c#. Thanks and God bless


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question