Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Saving multiple rows of gridview into database

$
0
0

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 "system.data.sqlclient.sqlparameter 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);
        con.Open();
        cmdd.ExecuteNonQuery();

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 asp.net with c#. Thanks and God bless



Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>