gpt4 book ai didi

sql - system.data.oledb.oledbexception :Syntax error in INSERT INTO Statement

转载 作者:行者123 更新时间:2023-12-04 05:10:15 24 4
gpt4 key购买 nike

我在 VB.NET 中有一个项目如下

Public Class MCARegis
Dim con As New OleDb.OleDbConnection()

Private Sub MCARegis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim da As OleDb.OleDbDataAdapter
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection()
con.ConnectionString = dbprovider
con.Open()
MsgBox("opened")
End Sub

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

Try
Dim da As OleDb.OleDbDataAdapter
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection()
con.ConnectionString = dbprovider
con.Open()

Dim sqlquery As String = "INSERT INTO MCA (URno,SName,Fname,CAddress,)" + "VALUES (" & CInt(txtUrn.Text) & ",'" & txtName.Text & "','" & txtFname.Text & "','" & txtCAdd.Text & "');"
Dim sqlcommand As New OleDb.OleDbCommand(sqlquery)

With sqlcommand
.CommandText = sqlquery
.Connection = con
.ExecuteNonQuery()
End With
MsgBox("Record Added")
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

End Class

当我尝试在 Insert into 语句中添加值时出现错误,对此有什么建议吗?
system.data.oledb.oledbexception:system.data.oledb.command.exceutecommandtexterrorhandling(oledbhresult hr)处的INSERT INTO语句中的语法错误
在systems.data.oledb.oledbcommand.executecommandtext(object&executeresult)......

在 system.data.oledb.oledbcomamand.executenonquery()

在第 29 行。

提前致谢....

最佳答案

替换 "INSERT INTO MCA (URno,SName,Fname,CAddress,)"来自 "INSERT INTO MCA (URno,SName,Fname,CAddress)" .您指定了一个多余的逗号

关于sql - system.data.oledb.oledbexception :Syntax error in INSERT INTO Statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14972347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com