Saving multiple rows of gridview into database

Discussion in 'C Programming' started by PetroTiburcio, Jun 1, 2013.

  1. PetroTiburcio

    PetroTiburcio

    Joined:
    May 17, 2013
    Messages:
    7
    Likes Received:
    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..." :

    Code (Text):
    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
     
    PetroTiburcio, Jun 1, 2013
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Saving all listbox rows to a database

    =?Utf-8?B?SnVzdGlu?=, Oct 21, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    5,830
    =?Utf-8?B?SnVzdGlu?=
    Oct 21, 2004
  2. Arjen Hoekstra
    Replies:
    0
    Views:
    782
    Arjen Hoekstra
    Aug 2, 2005
  3. BenCoo
    Replies:
    2
    Views:
    2,372
    =?Utf-8?B?TXVoYW1tYWQgTW9zYQ==?=
    Mar 4, 2007
  4. Enter The
    Replies:
    0
    Views:
    490
    Enter The
    Oct 18, 2007
  5. Andy B
    Replies:
    0
    Views:
    597
    Andy B
    Aug 3, 2008
  6. kate
    Replies:
    0
    Views:
    4,105
  7. VijayRama
    Replies:
    2
    Views:
    2,700
    Gregory A. Beamer
    Oct 12, 2009
  8. Nick
    Replies:
    4
    Views:
    723
    Eric Schwartz
    Oct 2, 2003
Loading...