大家好,下午好。
我在MySQL中有一个表,我曾经使用Datagridview显示它,这就是它的样子
Item Name Qty
Apple 0
Mango 0
我将点击导出按钮,接下来会发生的事情是Datagridview中的数据将被提取到与上图相同的Excel工作表中。
我将编辑提取的Excel数据,我会把任何我想要的东西,但现在这是我将要做的例子。
Item Name Qty
Apple 100
Mango 100
我将点击导入按钮,excel将覆盖Datagridview中的数据。
我的问题是如何使用Textbox1中的RefID更新Mysql数据库中datagridview中发生的更改?
我希望你们都能得到它,我正在使用VB.Net和Mysql
TY
This is my code of Importing
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "All Files (*.*)|*.*|Excel files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv|XLS Files (*.xls)|*xls"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
MsgBox("This will Overwrite your Current Data Proceed?")
Dim fi As New FileInfo(OpenFileDialog.FileName)
Dim FileName As String = OpenFileDialog.FileName
excel = fi.FullName
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties=Excel 12.0;")
dta = New OleDbDataAdapter("Select * From [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
DataGridView1.DataSource = dts
DataGridView1.DataMember = "[Sheet1$]"
conn.Close()
End If
With DataGridView1
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Item Code"
.Columns(1).HeaderCell.Value = "Description"
.Columns(2).HeaderCell.Value = "Delivery Date"
.Columns(3).HeaderCell.Value = "Stock On-Hand"
.Columns(4).HeaderCell.Value = "Ordering Level"
.Columns(5).HeaderCell.Value = "Order Qty"
.Columns(6).HeaderCell.Value = "Approved Qty"
.Columns(7).HeaderCell.Value = "UOM"
.Columns(8).HeaderCell.Value = "Unit Price"
.Columns(9).HeaderCell.Value = "Total"
.Columns(10).HeaderCell.Value = "Remarks"
End With
DataGridView1.Columns.Item(0).Width = 70
DataGridView1.Columns.Item(1).Width = 180
DataGridView1.Columns.Item(2).Width = 70
DataGridView1.Columns.Item(3).Width = 70
DataGridView1.Columns.Item(4).Width = 70
DataGridView1.Columns.Item(5).Width = 70
DataGridView1.Columns.Item(6).Width = 70
DataGridView1.Columns.Item(7).Width = 61
DataGridView1.Columns.Item(8).Width = 76
DataGridView1.Columns.Item(9).Width = 86
DataGridView1.Columns.Item(10).Width = 125
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells("Total").Value = row.Cells("Order Qty").Value * row.Cells("Unit Price").Value
Next
Dim total As Integer = 0
If DataGridView1.RowCount > 1 Then
For index As Integer = 0 To DataGridView1.RowCount - 1
total += Convert.ToInt32(DataGridView1.Rows(index).Cells(9).Value)
Next
TextBox7.Text = total
End If