请检查vb.net ms访问项目中的数字异常 [英] Please check the number exception in vb.net ms access project

查看:72
本文介绍了请检查vb.net ms访问项目中的数字异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建vb.net-ms访问数据库项目。

在其中一个插入命令中,我收到指向ExecuteNonQuery代码行的请检查数字异常。 />
我是编程新手。这是我的代码:

I am building vb.net-ms access database project.
In one of the "Insert" command, I am getting "Please check the number" exception pointing at ExecuteNonQuery code line.
I am new to programming. Here is my code:

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click

        If cbMachine.SelectedIndex <> -1 And _
        cbShift.SelectedIndex <> -1 And _
        cbWdiv.SelectedIndex <> -1 And _
        cbChky.SelectedIndex <> -1 And _
        cbBukby.SelectedIndex <> -1 And _
        cbRemarks.SelectedIndex <> -1 Then
            cmdInsert.CommandText = "INSERT INTO buktab ([Booking Date],[Machine Type],[Shift],[MS Division / Ward], Chowky, [Booked By], [Site Address], [Remarks]) VALUES(" &
                DateTimePicker1.Value.Date & ", '" & cbMachine.Text & "', '" & cbShift.Text & "', '" & cbWdiv.Text & "', '" & cbChky.Text & "', '" & cbBukby.Text & "', '" & cbSite.Text & "', '" & cbRemarks.Text & "');"

            cmdInsert.CommandType = CommandType.Text
            cmdInsert.Connection = cnnOLEDB
            cmdInsert.ExecuteNonQuery()

            MsgBox("Machine Booked Successfully!")
            'Resetting all comboboxes
            DateTimePicker1.Text = Today()
            cbMachine.SelectedIndex = -1
            cbShift.SelectedIndex = -1
            cbWdiv.SelectedIndex = -1
            cbChky.SelectedIndex = -1
            cbBukby.SelectedIndex = -1
            cbSite.Text = "Please Type Manually"
            cbRemarks.SelectedIndex = -1
        Else
            MsgBox(" Please Enter the Missing Values")
        End If
        cmdInsert.Dispose()
    End Sub


Please let me know, where I am going wrong. Any help in this regard is highly appreciated.
Thanks in advance.

推荐答案

不要使用字符串连接来构建类似的SQL查询。 Google针对SQL注入攻击找出你正在做的事情的原因是如此糟糕。
Do NOT use string concatenation to build an SQL query like that. Google for "SQL Injection Attack" to find out why what you're doing is so bad.


这篇关于请检查vb.net ms访问项目中的数字异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆