如何在VB.net中解决ExecuteNonQuery的问题

时间:2014-03-30 06:50:24

标签: vb.net ms-access

这是我在form.load中连接的代码

cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DatabaseCasanova.mdb"
cnn.Open()

这是我的SQL声明:

If ClientNoTextBox.Text <> "" And FirstNameTextBox.Text <> "" And LastNameTextBox.Text <> "" And AddressTextBox.Text <> "" And ContactNumberTextBox.Text <> "" And ProductCodeTextBox.Text <> "" And ProductNameTextBox.Text <> "" And UnitTextBox.Text <> "" And PriceTextBox.Text <> "" And TotalPriceTextBox.Text <> "" Then
        cmdinsert.CommandText = "INSERT INTO Orders(InvoiceNumber, ClientNo, FirstName, LastName, Address, ContactNumber, ProductCode, ProductName, Unit, Quantity, Price, TotalPrice, [DatePurchase], [DateToDeliver]) VALUES (" & Label4.Text & ", " & ClientNoTextBox.Text & ", '" & FirstNameTextBox.Text & "', '" & LastNameTextBox.Text & "', '" & AddressTextBox.Text & "', " & ContactNumberTextBox.Text & ", " & ProductCodeTextBox.Text & ", '" & ProductNameTextBox.Text & "', '" & UnitTextBox.Text & "', " & PriceTextBox.Text & ", " & TotalPriceTextBox.Text & ", '" & Label2.Text & "', '" & DateToDeliverDateTimePicker.Text & "')"
        cmdinsert.CommandType = CommandType.Text
        cmdinsert.ExecuteNonQuery()
        MsgBox("ADDED")
        ProductNameTextBox.Clear()
        PriceTextBox.Clear()
        FirstNameTextBox.Clear()
        TotalPriceTextBox.Clear()
        UnitTextBox.Clear()
        LastNameTextBox.Clear()
        AddressTextBox.Clear()
        ClientNoTextBox.Clear()
        ProductCodeTextBox.Clear()
        QuantityTextBox.Clear()
        ContactNumberTextBox.Clear()
    Else
        MsgBox("Complete your Transaction")
    End If
    cmdinsert.Dispose()

我不知道问题出在哪里,因为我尝试5x重新输入SQL语句。

MS Access是我的数据库和VB10程序

0 个答案:

没有答案