Sql 更新代码中的语法错误有关此问题的任何帮助
在我的更新查询中,以下代码中出现更新语法错误Sql 更新代码中的语法错误有关此问题的任何帮助,sql,vb.net,sql-update,Sql,Vb.net,Sql Update,在我的更新查询中,以下代码中出现更新语法错误 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim strup As String Try strup = "update MCA set urno=" & CInt(txtUrn.Text) & ",sname='" & t
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim strup As String
Try
strup = "update MCA set urno=" & CInt(txtUrn.Text) & ",sname='" & txtName.Text & "',fname='" & txtFname.Text & "',CAddress='" & txtCAdd.Text & "',PAddress='" & txtPAdd.Text & "',EmailID='" & txtEid.Text & "',cmbdate=" & CInt(cmbDate.Text) & ",cmbmonth='" & cmbMonth.Text & "',cmbyear=" & CInt(cmbYear.Text) & ",Gender='" & cmbGender.Text & "',Mobile" & CLng(txtMno.Text) & ",10PSSC=" & CInt(txt10Per.Text) & ",12PHSC=" & CInt(txt12Per.Text) & ",10YSSC='" & cmb10YofPass.Text & "',12YHSC='" & cmb12YofPass.Text & "',Course='" & cmbNameofGCourse.Text & "',gper=" & CInt(txtGPer.Text) & " WHERE urno =" & (txtUrn.Text) & ";"
Dim command As New OleDb.OleDbCommand(strup, con)
command.ExecuteNonQuery()
con.Open()
con.Close()
MsgBox("Record Updated")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
尝试:
您有
”,Mobile“&CLng(txtMno.Text)
而不是”,Mobile=“&CLng(txtMno.Text)
,与上述答案相同,并在最后一个值上添加了其中urno=“&(txtrn.Text)&”;“
表示数字或文本
如果是数字,则应将其转换为文本,然后应将其设置为其中urno='”&(txtrn.Text)&“;”
这就是您的查询的样子
strup = "update MCA set urno=" & CInt(txtUrn.Text) & ",sname='" & txtName.Text & "',fname='" & txtFname.Text & "',CAddress='" & txtCAdd.Text & "',PAddress='" & txtPAdd.Text & "',EmailID='" & txtEid.Text & "',cmbdate=" & CInt(cmbDate.Text) & ",cmbmonth='" & cmbMonth.Text & "',cmbyear=" & CInt(cmbYear.Text) & ",Gender='" & cmbGender.Text & "',Mobile=" & CLng(txtMno.Text) & ",10PSSC=" & CInt(txt10Per.Text) & ",12PHSC=" & CInt(txt12Per.Text) & ",10YSSC='" & cmb10YofPass.Text & "',12YHSC='" & cmb12YofPass.Text & "',Course='" & cmbNameofGCourse.Text & "',gper=" & CInt(txtGPer.Text) & " WHERE urno ='" & (txtUrn.Text) & "';"
非常感谢它能正常工作,但现在它抛出了一个异常,连接状态未关闭…?@user1897472在执行querytried之前放置
con.Open()。。。?在命令之前就试过了。executenonquery@user1897472然后移除con.Open()
。好像连接已经像往常一样打开了你是对的Andrey非常感谢伙计。。祝您愉快:)
strup = "update MCA set urno=" & CInt(txtUrn.Text) & ",sname='" & txtName.Text & "',fname='" & txtFname.Text & "',CAddress='" & txtCAdd.Text & "',PAddress='" & txtPAdd.Text & "',EmailID='" & txtEid.Text & "',cmbdate=" & CInt(cmbDate.Text) & ",cmbmonth='" & cmbMonth.Text & "',cmbyear=" & CInt(cmbYear.Text) & ",Gender='" & cmbGender.Text & "',Mobile=" & CLng(txtMno.Text) & ",10PSSC=" & CInt(txt10Per.Text) & ",12PHSC=" & CInt(txt12Per.Text) & ",10YSSC='" & cmb10YofPass.Text & "',12YHSC='" & cmb12YofPass.Text & "',Course='" & cmbNameofGCourse.Text & "',gper=" & CInt(txtGPer.Text) & " WHERE urno ='" & (txtUrn.Text) & "';"