0

更新クエリで、次のコードで更新構文エラーが発生します。

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
4

2 に答える 2

1

試す:

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) & ";"

あなた"',Mobile" & CLng(txtMno.Text)の代わりに"',Mobile=" & CLng(txtMno.Text)

于 2013-02-21T04:22:40.940 に答える
1

上記の回答と同じで、最後の値で
WHERE urno =" & (txtUrn.Text) & ";"ある数値またはテキストに追加します。

数値の場合は変換する必要があり、テキストの場合は次のように入力する必要があります
WHERE urno ='" & (txtUrn.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) & "';"
于 2013-02-21T04:41:20.220 に答える