没有为一个或多个必需参数(访问)提供值

时间:2018-09-06 06:45:14

标签: vb.net ms-access

我有2个带有这些字段的数据表

* dataordner

  1. 归档日期/时间(datetimepicker,它已经是数据了)

  2. 存储短文本(组合框)

  3. BulanOrdner ShortText(组合框)

  4. TahunOrdner日期/时间(datetimepicker)

* datalemari

  1. 归档日期/时间(datetimepicker,它已经是数据了)

  2. 存储短文本(组合框)

  3. Lemari短文本(组合框)

  4. BulanOrdner ShortText(组合框)

  5. 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

1 个答案:

答案 0 :(得分:0)

我可能有一些控件的值为nullNothing,您可以使用带有断点的调试来检查空值,或者可能存在未初始化的对象。

您也可以尝试以下代码:

注意 我建议您改用参数化查询

  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