我有2个带有这些字段的数据表
* dataordner
归档日期/时间(datetimepicker,它已经是数据了)
存储短文本(组合框)
BulanOrdner ShortText(组合框)
TahunOrdner日期/时间(datetimepicker)
* datalemari
归档日期/时间(datetimepicker,它已经是数据了)
存储短文本(组合框)
Lemari短文本(组合框)
BulanOrdner ShortText(组合框)
TahunOrdner日期/时间(datetimepicker)
现在我很困惑为什么我错了
我尝试过的事情:
我已经完成了我的代码,但始终会出错,并显示错误“没有提供更多值...。”
我用组合框(存储)中的if else调用2表
这些是我的代码序列,我认为对于组合框中的选定项目都是如此
注释:
存储=组合框
Private Sub storage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles storage.SelectedIndexChanged
If storage.SelectedIndex = 1 Then
groupordner.Visible = True
grouplemari.Visible = False
Else
If storage.SelectedIndex = 2 Then
groupordner.Visible = False
grouplemari.Visible = True
End If
End If
End Sub
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
If storage.SelectedItem = "Ordner" Then
str = "Update dataordner set Storage = " & storage.Text & ", BulanOrdner = " & bulanordner.Text & ", TahunOrdner = '" & tahunordner.Value & "' Where Archive = '" & tanggalarchive.Value & "'"
proses.ExecuteNonQuery(str)
MsgBox("Data Has Been Saved", MessageBoxButtons.OK)
Call bersih()
Call data_penjualan()
Else
If storage.SelectedItem = "Lemari" Then
str = "Update datalemari set Storage = " & storage.Text & ", Lemari = " & lemari.Text & ", BulanLemari = " & bulanlemari.Text & ", TahunLemari = '" & tahunlemari.Value & "' Where Archive = '" & tanggalarchive.Value & "'"
proses.ExecuteNonQuery(str)
MsgBox("Data Has Been Saved", MessageBoxButtons.OK)
Call bersih()
Call data_penjualan()
End If
End If
End Sub
答案 0 :(得分:0)
我可能有一些控件的值为null
或Nothing
,您可以使用带有断点的调试来检查空值,或者可能存在未初始化的对象。
您也可以尝试以下代码:
注意 :我建议您改用参数化查询
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
If storage.SelectedItem Is Nothing Then
MsgBox("Plese Select the item first", MsgBoxStyle.Exclamation)
Else
If conn.State <> ConnectionState.Open Then
conn.Open() '' Assuming conn is your OleDbConnection
End If
Dim cmd As OleDbCommand = conn.CreateCommand
Try
If storage.SelectedItem = "Ordner" Then
Str = "Update dataordner set Storage = " & storage.Text & ", BulanOrdner = " & bulanordner.Text & ", TahunOrdner = '" & tahunordner.Value & "' Where Archive = '" & tanggalarchive.Value & "'"
cmd.CommandText = Str
cmd.ExecuteNonQuery()
MsgBox("Data Has Been Saved", MessageBoxButtons.OK)
Call bersih()
Call data_penjualan()
Else
If storage.SelectedItem = "Lemari" Then
Str = "Update datalemari set Storage = " & storage.Text & ", Lemari = " & lemari.Text & ", BulanLemari = " & bulanlemari.Text & ", TahunLemari = '" & tahunlemari.Value & "' Where Archive = '" & tanggalarchive.Value & "'"
cmd.CommandText = Str
cmd.ExecuteNonQuery()
MsgBox("Data Has Been Saved", MessageBoxButtons.OK)
Call bersih()
Call data_penjualan()
End If
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
Finally
conn.Close()
End Try
End If
End Sub