datagridview中的批量更新 [英] batch update in datagridview

查看:104
本文介绍了datagridview中的批量更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是vb.net的新手。我有一个包含以下列的表: -
date,name,price,open,close,sold。
这里我将此表绑定到gridview,其中close和sold是未绑定的列,在运行时填充。以下是代码: -

公共 Sub gridbind()

Hi all,
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:-

Public Sub gridbind()

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屋!

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