如何使用Vb.net在DataBase中保存GridView数据 [英] How TO Save GridView Data In DataBase using Vb.net
问题描述
我想将网格视图数据保存到SQL DATaABASE
但我不想从gridview保存所有数据
只保存那些在gridview中更改或更新的数据
i分享图片详情
详情
a网格视图
和网格视图中的巨大数据显示
和GridView中有一个ComboBox
i想要用户更改ComboBox值
所以这些行只在Sql DataBase中更新因为如果所有数据都在SQL中更新所以有大量数据
我该怎么办
..
对于Grid View我使用
DataSet
DataTable
DataRow
- ---
点击此处查看IMage以进一步说明
i want to save Grid View Data into SQL DATaABASE
but i dont want that all data save from gridview
just save those data who changing or update in gridview
i share detail in image
Detail
a GRID VIEW
and a Huge Data Show In Grid View
and There is a ComboBox In GridView
i want That if User Change ComboBox Value
so These Rows Only Update in Sql DataBase Because if all data update in SQL so there is huge data
what should i do
..
For Grid View I Am using
DataSet
DataTable
DataRow
----
Click Here To View IMage to Further Explain
推荐答案
你可以这样做......
1.OnRowUpdating
事件检查是否更改了ComboBox
值。
- IF值改变
- 更新行
You can do like below...
1.OnRowUpdating
event check whether thatComboBox
value is changed or not.
- IF value is changed
- update the row
- don'更新
尝试
http ://www.vb-helper.com/howto_net_datagrid.html [ ^ ]
http://www.dreamincode.net/forums/topic/68848-how-to -add-delete-and-update-database-using-datagridview / [ ^ ]
http://www.daniweb.com/web-development/ aspnet / threads / 364187 / save-all-all-values-of-gridview-in-database-in-vb.net-code [ ^ ]
Try
http://www.vb-helper.com/howto_net_datagrid.html[^]
http://www.dreamincode.net/forums/topic/68848-how-to-add-delete-and-update-database-using-datagridview/[^]
http://www.daniweb.com/web-development/aspnet/threads/364187/save-all-all-values-of-gridview-in-database-in-vb.net-code[^]
Try
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim con As New SqlConnection(connectionString)
con.Open()
Dim cmd As New SqlCommand("INSERT INTO BookDetail VALUES(@Printing_Method,@year,@Month,@Faculty,@Course_Code,@Block,@Medium)")
cmd.CommandType = CommandType.Text
' Dim adapFam As New SqlDataAdapter
For i As Integer = 0 To DataGridView1.Rows.Count - 1
cmd.Parameters.AddWithValue("@Printing_Method", DataGridView1.Rows(i).Cells(0).Value.ToString())
cmd.Parameters.AddWithValue("@year", DataGridView1.Rows(i).Cells(1).Value.ToString())
cmd.Parameters.AddWithValue("@Month", DataGridView1.Rows(i).Cells(2).Value.ToString())
cmd.Parameters.AddWithValue("@Faculty", DataGridView1.Rows(i).Cells(3).Value.ToString())
cmd.Parameters.AddWithValue("@Course_Code", DataGridView1.Rows(i).Cells(4).Value.ToString())
cmd.Parameters.AddWithValue("@Block", DataGridView1.Rows(i).Cells(5).Value.ToString())
cmd.Parameters.AddWithValue("@Medium", DataGridView1.Rows(i).Cells(6).Value.ToString())
cmd.Connection = con
cmd.ExecuteNonQuery()
'adapFam.InsertCommand.ExecuteNonQuery()
Next
con.Close()
MessageBox.Show("Successfully saved", "Inventory", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
这篇关于如何使用Vb.net在DataBase中保存GridView数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!