VB.net程序在运行期间没有错误,但update命令在ACCESS数据库中不起作用

VB.net程序在运行期间没有错误,但update命令在ACCESS数据库中不起作用,vb.net,ms-access-2010,insert-update,Vb.net,Ms Access 2010,Insert Update,VB.net程序在运行期间没有错误,但update命令在ACCESS数据库中不起作用。这是我的第一个问题,所以如果有任何错误。。。先说声对不起 Dim con As New OleDbConnection Try Dim dslno As String Dim wno As String Dim rno As String Dim qnotaken As String Dim qnosold As Str

VB.net程序在运行期间没有错误,但update命令在ACCESS数据库中不起作用。这是我的第一个问题,所以如果有任何错误。。。先说声对不起

 Dim con As New OleDbConnection
    Try

        Dim dslno As String
        Dim wno As String
        Dim rno As String
        Dim qnotaken As String
        Dim qnosold As String
        Dim damage As String
        Dim cinform As String   

        con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Shop Database.accdb")

        con.Open()

        If DataGridView1.Rows.Count > 0 Then
            Dim cmd As New OleDbCommand
            cmd.Connection = con
            cmd.CommandType = Data.CommandType.Text
            Dim values As String = ""

            For i As Integer = 0 To DataGridView1.Rows.Count - 2

                dslno = DataGridView1.Rows(i).Cells(0).Value
                wno = DataGridView1.Rows(i).Cells(2).Value
                rno = DataGridView1.Rows(i).Cells(3).Value
                qnotaken = DataGridView1.Rows(i).Cells(4).Value
                qnosold = DataGridView1.Rows(i).Cells(5).Value
                damage = DataGridView1.Rows(i).Cells(6).Value
                cinform = DataGridView1.Rows(i).Cells(7).Value

                If wno = "" Then
                    wno = 0
                End If
                If rno = "" Then
                    rno = 0
                End If
                If qnotaken = "" Then
                    qnotaken = 0
                End If
                If damage = "" Then
                    damage = 0
                End If
                If qnosold = "" Then
                    qnosold = 0
                End If
                If cinform = "" Then
                    cinform = "No"
                End If

                Dim strcommandText As String = "UPDATE  PRODUCT SET  ProductName='" + DataGridView1.Rows(i).Cells(1).Value & "', WPrice = " + wno + ",RPrice=" + rno + ",Damage=" + damage + ",TakenQuantity=" + qnotaken + ",SoldQuantity=" + qnosold + ",CONTACTINFORM='" + cinform + "'"


                values = strcommandText + (" Where SlNo=" + dslno).ToString
                MsgBox(values)
                cmd.CommandText = values
                cmd.ExecuteNonQuery()


            Next i



        End If


    Catch ex As Exception
        MsgBox("Enter all Details")
        MsgBox(ex.ToString)
        con.Close()
    Finally
        If con.State <> ConnectionState.Closed Then
            MsgBox("Sucess")
            con.Close()


        End If
    End Try  
Dim con作为新的OLEDB连接
尝试
数字单反串
暗wno作为字符串
Dim rno作为字符串
将qnotaken变暗为字符串
变暗qnosold为字符串
像绳子一样暗损
像字符串一样变暗
con=New-OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;数据源=| DataDirectory | \Shop-Database.accdb”)
con.Open()
如果DataGridView1.Rows.Count>0,则
Dim cmd作为新的OLEDB命令
cmd.Connection=con
cmd.CommandType=Data.CommandType.Text
将值设置为字符串=“”
对于i As Integer=0到DataGridView1.Rows.Count-2
dslno=DataGridView1.Rows(i).Cells(0).Value
wno=DataGridView1.Rows(i).Cells(2).Value
rno=DataGridView1.Rows(i).Cells(3).Value
qnotaken=DataGridView1.Rows(i).Cells(4).Value
qnosold=DataGridView1.Rows(i).Cells(5).Value
损坏=DataGridView1.行(i).单元格(6).值
cinform=DataGridView1.Rows(i).Cells(7).Value
如果wno=”“,则
wno=0
如果结束
如果rno=”“,则
rno=0
如果结束
如果qnotaken=“”,则
qnotaken=0
如果结束
如果损坏=“则
损坏=0
如果结束
如果qnosold=“”,则
qnosold=0
如果结束
如果cinform=“”,则
cinform=“否”
如果结束
Dim strcommandText为String=“UPDATE PRODUCT SET ProductName=”+DataGridView1.Rows(i).Cells(1).Value&“,”WPrice=“+wno+”,RPrice=“+rno+”,Damage=“+Damage+”,takenkantity=“+qnotaken+”,SoldQuantity=“+qnosold+”,CONTACTINFORM=”+cinform+“”
值=strcommandText+(“其中SlNo=“+dslno”).ToString
MsgBox(值)
cmd.CommandText=值
cmd.ExecuteNonQuery()
接下来我
如果结束
特例
MsgBox(“输入所有详细信息”)
MsgBox(例如ToString)
con.Close()
最后
如果con.State ConnectionState.已关闭,则
MsgBox(“成功”)
con.Close()
如果结束
结束尝试
我相信您可以帮助我,因此提前谢谢。

如果您开始使用参数化查询,您将节省大量时间调试代码中的小错误:

 Dim con As New OleDbConnection
    Try

        Dim dslno As String
        Dim wno As String
        Dim rno As String
        Dim qnotaken As String
        Dim qnosold As String
        Dim damage As String
        Dim cinform As String   

        con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Shop Database.accdb")

        con.Open()

        If DataGridView1.Rows.Count > 0 Then
            Dim cmd As New OleDbCommand
            cmd.Connection = con
            cmd.CommandType = Data.CommandType.Text
            Dim values As String = ""

            For i As Integer = 0 To DataGridView1.Rows.Count - 2

                dslno = DataGridView1.Rows(i).Cells(0).Value
                wno = DataGridView1.Rows(i).Cells(2).Value
                rno = DataGridView1.Rows(i).Cells(3).Value
                qnotaken = DataGridView1.Rows(i).Cells(4).Value
                qnosold = DataGridView1.Rows(i).Cells(5).Value
                damage = DataGridView1.Rows(i).Cells(6).Value
                cinform = DataGridView1.Rows(i).Cells(7).Value

                If wno = "" Then
                    wno = 0
                End If
                If rno = "" Then
                    rno = 0
                End If
                If qnotaken = "" Then
                    qnotaken = 0
                End If
                If damage = "" Then
                    damage = 0
                End If
                If qnosold = "" Then
                    qnosold = 0
                End If
                If cinform = "" Then
                    cinform = "No"
                End If

                Dim strcommandText As String = "UPDATE  PRODUCT SET  ProductName='" + DataGridView1.Rows(i).Cells(1).Value & "', WPrice = " + wno + ",RPrice=" + rno + ",Damage=" + damage + ",TakenQuantity=" + qnotaken + ",SoldQuantity=" + qnosold + ",CONTACTINFORM='" + cinform + "'"


                values = strcommandText + (" Where SlNo=" + dslno).ToString
                MsgBox(values)
                cmd.CommandText = values
                cmd.ExecuteNonQuery()


            Next i



        End If


    Catch ex As Exception
        MsgBox("Enter all Details")
        MsgBox(ex.ToString)
        con.Close()
    Finally
        If con.State <> ConnectionState.Closed Then
            MsgBox("Sucess")
            con.Close()


        End If
    End Try  
cmd.CommandText=_
“更新[产品]集”和_
“产品名称=?,”和_
“WPrice=?,”和_
“RPrice=?,”和_
“损害=?,”和_
“TakenQuantity=?,”和_
“SoldQuantity=?,”和_
“联系人通知=?”和_
“其中SlNo=?”
cmd.Parameters.AddWithValue(“?”,DataGridView1.Rows(i).Cells(1).Value)
cmd.Parameters.AddWithValue(“?”,wno)
cmd.Parameters.AddWithValue(“?”,rno)
cmd.Parameters.AddWithValue(“?”,损坏)
cmd.Parameters.AddWithValue(“?”,qnotaken)
cmd.Parameters.AddWithValue(“?”,qnosold)
cmd.Parameters.AddWithValue(“?”,cinform)
cmd.Parameters.AddWithValue(“?”,dslno)
Dim rowsAffected As Integer=cmd.ExecuteNonQuery()

始终使用参数以避免SQL注入。不知道,但请尝试将
ProductName='“+
更改为
ProductName='”&
为什么在strcommandText+(“Where SlNo=“+dslno”)中使用“.ToString”?如果您将最后一个字符串“VALUES”放在“Execute”命令之前,我们可以看到SQL查询中是否有任何错误。至少使用string.Format()使其可读。您仍然在使用
+
您应该使用
&
的地方。否则,就无法诊断,因为您声称没有任何错误。您需要学习在这些情况下使用调试器。对不起,先生,我更改了代码,但没有更改。但他们的是两个警告1。警告1无法解析此引用。找不到程序集“Microsoft.VisualBasic.PowerPacks.Vs,版本=10.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a,processorArchitecture=MSIL”。检查以确保磁盘上存在程序集。如果代码需要此引用,则可能会出现编译错误。Sujithshop 2。警告2无法找到引用的组件“Microsoft.VisualBasic.PowerPacks.Vs”。 Sujithshop@user3005013对不起,那些警告对我来说没有任何意义。当你使用旧代码时,你得到了吗?