TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Petro Tiburcio
NA
15
15.9k
Saving multiple rows of gridview into database
Jun 1 2013 10:18 AM
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
Reply
Answers (
3
)
how can count student
How to connect an Access Database to a C# Console Applicatio