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
SAM J
NA
24
33.2k
Insert data from datagrid to Databse
Mar 24 2011 2:54 PM
inserting one row at a time....
for (int count = 0; count < dataGridView1.RowCount; count++)
{
// here i am auto generating the ID
scd = new SqlCommand("Select count(Followup_ID) from Client_Followup", cnn);
cnn.Open();
object result = scd.ExecuteScalar();
cnn.Close();
auto = ("CF" + (int.Parse(result.ToString()) + 1));
//inserting my datagrid values to database
scd = new SqlCommand("insert into Client_Followup(Followup_ID, Vac_ID, Vac_Designa) values(@Followup_ID, @Vac_ID, @Vac_Designa)", cnn);
scd.Parameters.AddWithValue("@Followup_ID", SqlDbType.VarChar).Value = auto;
scd.Parameters.AddWithValue("@Vac_ID", SqlDbType.VarChar).Value = dataGridView1[0, count].Value.ToString();
scd.Parameters.AddWithValue("@Vac_Designa", SqlDbType.VarChar).Value = dataGridView1[1, count].Value.ToString();
cnn.Open();
scd.ExecuteNonQuery();
MessageBox.Show("Row " + count + " Inserted Successfully");
cnn.Close();
Is this the right way to insert the rows one at a time??
Reply
Answers (
6
)
passing cell's value of gridview in hyperlink navigate url...
how to using printer to print report