【问题标题】:No value given for one or more required parameters (access)没有为一个或多个必需参数指定值(访问)
【发布时间】:2018-09-06 06:45:13
【问题描述】:

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

*数据排序器

  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

【问题讨论】:

  • 您是否真的查看了正在执行的 SQL 代码,而不仅仅是构造它的代码?当数据导致问题时,查看导致问题的数据确实应该是不费吹灰之力。
  • @jmcilhinney 我觉得我的代码是对的,database和vb是非常相关的,没有假的,我只是很困惑为什么它不想进入
  • 您查看过它以确保它是正确的吗?如果不是,那么您认为无关紧要。

标签: vb.net ms-access


【解决方案1】:

可能有一些控件的值是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

【讨论】:

  • 我已经尝试使用该代码,但它仍然无法正常工作,并且仍然出现相同的错误:((
猜你喜欢
  • 1970-01-01
  • 2011-01-23
  • 2017-12-25
  • 2015-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多