datagridview中的批量更新 [英] batch update in datagridview
问题描述
大家好,我是vb.net的新手。我有一个包含以下列的表: - 公共
date,name,price,open,close,sold。
这里我将此表绑定到gridview,其中close和sold是未绑定的列,在运行时填充。以下是代码: -
Hi all, Public
i m new in vb.net. I have a table with following columns:-
date,name,price,open,close,sold.
here i am binding this table to gridview in which close and sold are unbound columns which are filled during runtime. Here is the code:-
Dim offset As 整数 = -1
Dim offset As Integer = -1
Dim NewDate 如 String = DateAdd(DateInterval.Day,offset,Today)
Dim NewDate As String = DateAdd(DateInterval.Day, offset, Today)
Dim sql As < font color ="#0000ff"size = 2>字符串 = " select name,price,[open] from LotterySale,其中date ='" & NewDate& "'或date ='" & DateTime.Now.Date& "'"
Dim sql As String = "select name,price,[open] from LotterySale where date = '" & NewDate & "' or date ='" & DateTime.Now.Date & "'"
Dim adp As 新 SqlDataAdapter(sql,con)
Dim adp As New SqlDataAdapter(sql, con)
Dim ds As New DataSet
Dim ds As New DataSet
adp.Fill(ds, " lotterysale" )
adp.Fill(ds, "lotterysale")
ds.Tables( " Lotterysale" )。列.Add( 新 DataColumn( "关闭" , GetType ( 整数 )))
ds.Tables("Lotterysale").Columns.Add(New DataColumn("Close", GetType(Integer)))
ds.Tables( " Lotterysale" )。Columns.Add( 新 DataColumn( " NoOfTickets" , GetType ( 整数 )))
ds.Tables("Lotterysale").Columns.Add(New DataColumn("NoOfTickets", GetType(Integer)))
ds.Tables( " Lotterysale" )。列( " NoOfTickets" )。Expression = " open - close"
ds.Tables("Lotterysale").Columns("NoOfTickets").Expression = "open - close"
ds.Tables( " Lotterysale" )。Columns.Add( New DataColumn( "已售出" , GetType ( Inte ger ), "(open - close)* price" ) )
ds.Tables("Lotterysale").Columns.Add(New DataColumn("Sold", GetType(Integer), "(open - close) * price"))
Me .LotteryGrid.AutoGenerateColumns = False
Me.LotteryGrid.AutoGenerateColumns = False
Me .LotteryGrid.EditMode = DataGridViewEditMode.EditOnEnter
Me.LotteryGrid.EditMode = DataGridViewEditMode.EditOnEnter
LotteryGrid.DataSource = ds.Tables( "LotterySale" )
LotteryGrid.DataSource = ds.Tables("LotterySale")
Dim < font size = 2> name As New DataGridViewTextBoxColumn
Dim name As New DataGridViewTextBoxColumn
name
With name
.HeaderText = " Name"
.HeaderText = "Name"
.Name = " Name"
.Name = "Name"
.DataPropertyName = " Name"
.DataPropertyName = "Name"
结束 使用
End With
Dim price As New DataGridViewTextBoxColumn
Dim price As New DataGridViewTextBoxColumn
price
With price
.HeaderText = "价格"
.HeaderText = "Price"
.Name = "价格"
.Name = "price"
.DataPropertyName = " price"
.DataPropertyName = "price"
结束 使用
End With
Dim op en As New DataGridViewTextBoxColumn
Dim open As New DataGridViewTextBoxColumn
使用 打开
With open
.HeaderText = "打开"
.HeaderText = "Open"
.Name = "打开"
.Name = "Open"
.DataPropertyName = "打开"
.DataPropertyName = "open"
结束 < font color ="#0000ff"size = 2>使用
End With
Dim close As New < font size = 2> DataGridViewTextBoxColumn
Dim close As New DataGridViewTextBoxColumn
close
With close
.HeaderText = " Close"
.HeaderText = "Close"
.Name = " close"
.Name = "close"
.DataPropertyName = " Close"
.DataPropertyName = "Close"
结束 使用
End With
Dim NoOfTickets As 新 DataGridViewTextBoxColumn
Dim NoOfTickets As New DataGridViewTextBoxColumn
使用 NoOfTickets
With NoOfTickets
.HeaderText = " No。票证"
.HeaderText = "No. Of Tickets"
.Name = " NoOfTickets"
.Name = "NoOfTickets"
.DataPropertyName = " NoOfTickets"
.DataPropertyName = "NoOfTickets"
End With
End With
Dim sold < font color ="#0000ff"size = 2> As New DataGridViewTextBoxColumn
Dim sold As New DataGridViewTextBoxColumn
已售出
With sold
.HeaderText = " Sold"
.HeaderText = "Sold"
.Name = "已售出"
.Name = "Sold"
.DataPropertyName = "已售出" ;
.DataPropertyName = "Sold"
结束
End With
LotteryGrid.Columns.Add(name)
LotteryGrid.Columns.Add(name)
LotteryGrid.Columns.Add(price)
LotteryGrid.Columns.Add(price)
LotteryGrid.Columns.Add(open)
LotteryGrid.Columns.Add(open)
LotteryGrid.Columns.Add(close)
LotteryGrid.Columns.Add(close)
LotteryGrid.Columns.Add(NoOfTickets)
LotteryGrid.Columns.Add(NoOfTickets)
LotteryGrid.Columns.Add(已售)
LotteryGrid.Columns.Add(sold)
LotteryGrid.CurrentCell = LotteryGrid.Rows(0).Cells(3)
LotteryGrid.CurrentCell = LotteryGrid.Rows(0).Cells(3)
结束 Sub
现在我想用datagridview中的值更新我的表格。我不知道该怎么做所以请帮助我!
End Sub
Now i want to update my table with the values in datagridview. I dont know how to do this so please help me!
推荐答案
你好,
因为你绑定了LotteSale表的网格(LotteryGrid.DataSource = ds.Tables("LotterySale"))LotterySale表应该对网格进行所有更改。如果您需要检查值,可以通过ds.Tables("LotterySale")导航。行集合。
如果有帮助请告诉我
Hello,
Because you bound the grid to the LotteySale table ( LotteryGrid.DataSource = ds.Tables( "LotterySale" ) ) the LotterySale table should have all the changes made to the grid. If you need to inspect the values you can do so navigating through ds.Tables("LotterySale").Rows Collection.
Please let me know if this helps
这篇关于datagridview中的批量更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!