将GridView的内容保存到数据库中 [英] Saving contents of a gridview into database

查看:83
本文介绍了将GridView的内容保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是从连接gridview中的三个表的数据库中填充值,我想将同一gridview的内容保存到另一个表中.

我可以保存一行,但是我的gridview包含多行,我想通过单击按钮保存它们.

请帮帮我的朋友.

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.

推荐答案

用于gridview的循环以保存所有行.
Use for loop for gridview to save all the rows.


Hello Vivek,


试试这个

受保护的子SaveButton(ByVal发送者为对象,ByVal e为EventArgs)
昏暗的conn作为新的SqlConnection("your_connection_string")
conn.Open()
对于每个gvr,作为GridView1.Rows中的GridViewRow
Dim data1 As String = gvr.Cells(0).Text
''从BoundField中的每一行中获取数据
Dim data2 As String = DirectCast(gvr.FindControl("Label1"),Label).文本
''从每行的TemplateField中的控件中获取数据
昏暗的cmd作为新的SqlCommand("insert_sql",conn)
''使用上述数据生成插入sql
cmd.ExecuteNonQuery()
下一个
conn.Close()
结束子

谢谢
sanjeev
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


这篇关于将GridView的内容保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆