Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If Not sqlcon.State = ConnectionState.Open Then
' open connection
sqlcon.Open()
End If
com2 = New SqlCommand("UPDATE frames SET [number] = [number] + '" & number.Text & "' where measure = '" & measure.Text & "'", sqlcon)
com2.ExecuteNonQuery()
com = New SqlCommand("insert into frames ([number],measure) values('" & number.Text & "','" & measure.Text & "'),('" & number1.Text & "','" & measure1.Text & "')", sqlcon)
com.ExecuteNonQuery()
End If
Next
End Sub
这是我正在处理的代码,但我搜索更好的方法并找到这些
com2 = New SqlCommand("UPDATE frames SET [number] = [number] + '" & number.Text & "' where measure = '" & measure.Text & "' if @@rowcount=0 insert into frames ([number],measure) values('" & number.Text & "','" & measure.Text & "'),('" & number1.Text & "','" & measure1.Text & "'", sqlcon)
com2.ExecuteNonQuery()
但它给了我错误'93。附近的语法不正确......... 93.5是在measure.text中存在的值,但所有的sql语句都没有,除了这个错误我不知道为什么 我尝试过另一种方式
com = New SqlCommand("IF NOT EXISTS (SELECT * FROM frames) BEGIN insert into frames ([number],measure) values('" & number.Text & "','" & measure.Text & "'),('" & number1.Text & "','" & measure1.Text & "') END ELSE BEGIN UPDATE frames SET [number] = [number] + '" & number.Text & "' where measure = '" & measure.Text & "'", sqlcon)
com2 = New SqlCommand("IF EXISTS (SELECT * FROM frames) THEN BEGIN Update frames set [number] = [number] + '" & number.Text & "' where measure = '" & measure.Text & "' End ELSE bEGIN INSERT INTO frames ([number],measure) values('" & number.Text & "','" & measure.Text & "'),('" & number1.Text & "','" & measure1.Text & "' END", sqlcon)
com2.ExecuteNonQuery()
我收到此错误“****关键字'THEN'附近的语法不正确。
关键字“ELSE”附近的语法不正确。
关键字“END”。****“或
附近的语法不正确我收到此错误“'61 .19'附近的语法不正确。” ......... 61.19是measure.text中存在的值
请帮我找到没有错误的方法,或者这些????
我听说过交易但是我这样搜索并且什么都不懂......