Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here am populating values from database joining three tables in gridview and i want to save the content of same gridview into another table.

i can save one row but my gridview contains multiple row and i want to save those by button click.

please help me out friends.
Posted

Use for loop for gridview to save all the rows.
 
Share this answer
 
Hello Vivek,


try this

Protected Sub SaveButton(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As New SqlConnection("your_connection_string")
conn.Open()
For Each gvr As GridViewRow In GridView1.Rows
Dim data1 As String = gvr.Cells(0).Text
'get data from BoundField in each row
Dim data2 As String = DirectCast(gvr.FindControl("Label1"), Label).Text
'get data from control in TemplateField in each row
Dim cmd As New SqlCommand("insert_sql", conn)
'generate insert sql using above data
cmd.ExecuteNonQuery()
Next
conn.Close()
End Sub

thanks
sanjeev
 
Share this answer
 
Comments
Vivek Shankar 16-Dec-11 4:07am    
Thanku

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900