我目前正在制作一个时间表程序,目前有一个DataGridView,用户可以在其中输入数据,并且应该能够保存该数据,这样当程序再次打开时,数据仍然存在。我尝试过很多选择,但似乎没什么用。我目前有这个代码:
Try
Me.Validate()
Me.Daily_formatBindingSource.EndEdit()
Me.Daily_formatTableAdapter.Update(Me.CalenderD1DataSet.Daily_format)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
答案 0 :(得分:0)
这是我的一个程序中的一段代码,它将数据从Datagridview保存到数据库中,您应该明白这一点:
For i = 0 To DG_add_stock.Rows.Count - 1
Dim stock_code As String = CStr(DG_add_stock.Rows(i).Cells("Code").Value)
Dim stock_desc As String = CStr(DG_add_stock.Rows(i).Cells("Description").Value)
Dim qty As String = CStr(DG_add_stock.Rows(i).Cells("Qty").Value)
Dim price As String = CStr(DG_add_stock.Rows(i).Cells("Price").Value)
Dim tax_rate As String = CStr(DG_add_stock.Rows(i).Cells("Tax_Rate").Value)
Dim line_total As String = CStr(DG_add_stock.Rows(i).Cells("Line_Total").Value)
''' Save the data in a database or update existing data
Next
然后显示数据:
DG_Maintenance_Stock.Rows.Clear()
''' Get the data from the database
For add_items = 0 To row_count - 1
''' Load values from each row
DG_Maintenance_Stock.Rows.Add(code_list, desc_list, qty_list, tax_rate_list, price_list)
DG_Maintenance_Stock.Sort(maintenance_stock_Code, System.ComponentModel.ListSortDirection.Ascending)
Next