我一直有这个问题,我的搜索引起了更多的困惑。目前我拥有的是一个访问数据库,当windows窗体加载时,它会提取一个技术列表并将其放入ComboBox。一旦您选择了您正在寻找的技术,您点击一个按钮就会拉出日期(当他们的保险到期时)。我已经成功地获取它来拉日期并让它填充DateTimePicker的截止日期。
我遇到问题的时候,就是我更改日期并尝试将其保存回数据库。我没有收到任何错误,我甚至得到了我的#34;记录保存"信息。我感到茫然,任何帮助都会有所帮助。
Imports System.Data.OleDb
Public Class GateTechTesting
Private Sub GateTechTesting_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MainTechDataFile As String
Dim MainTechConnString As String
Dim MainTechConnection As OleDbConnection = New OleDbConnection
Dim MR As OleDbDataReader
Dim provider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
MainTechDataFile = "C:\Users\Jmcn\Desktop\GateTechDBTest.accdb"
MainTechConnString = provider & MainTechDataFile
MainTechConnection.ConnectionString = MainTechConnString
MainTechConnection.Open()
Dim query As String = "Select * From Gtech"
Dim command As OleDbCommand = New OleDbCommand(query, MainTechConnection)
MR = command.ExecuteReader
While MR.Read()
ComboBox1.Items.Add(MR("Gate Tech").ToString)
End While
MainTechConnection.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.SelectedItem = "" Then
MessageBox.Show("Nothing Selected")
Else
Dim setech As String = ComboBox1.SelectedItem
Dim MainTechDataFile As String
Dim MainTechConnString As String
Dim MainTechConnection As OleDbConnection = New OleDbConnection
Dim MR As OleDbDataReader
Dim provider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
MainTechDataFile = "C:\Users\Jmcn\Desktop\GateTechDBTest.accdb"
MainTechConnString = provider & MainTechDataFile
MainTechConnection.ConnectionString = MainTechConnString
MainTechConnection.Open()
Dim query As OleDbCommand = New OleDbCommand("Select * From Gtech WHERE [Gate Tech] = @tech", MainTechConnection)
query.Parameters.AddWithValue("@tech", setech)
MR = query.ExecuteReader
While MR.Read()
DateTimePicker1.Text = MR("Liability").ToString
End While
MainTechConnection.Close()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim satech As String = ComboBox1.SelectedItem
Dim cnnOLEDB As OleDbConnection = New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
cnnOLEDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =C:\Users\Jmcn\Desktop\GateTechDBTest.accdb"
cnnOLEDB.Open()
cmdUpdate.CommandText = "UPDATE Gtech SET Liability = @newdate WHERE [Gate Tech] = @tech" '& CInt(store)
cmdUpdate.Parameters.AddWithValue("@tech", satech)
cmdUpdate.Parameters.AddWithValue("@newdate", DateTimePicker1.Value.Date)
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.Connection = cnnOLEDB
cmdUpdate.ExecuteNonQuery()
MsgBox("Record updated.")
cmdUpdate.Dispose()
cnnOLEDB.Close()
Catch ex As Exception
End Try
End Sub
结束班