提问人:MGC 提问时间:10/13/2023 最后编辑:Dale KMGC 更新时间:10/13/2023 访问量:79
无法查看此错误的位置:System.Data.SqlClient.SqlException:“'10'附近的语法不正确。[复制]
Cannot see where this error is: System.Data.SqlClient.SqlException: 'Incorrect syntax near '10'.' [duplicate]
问:
我看不到错误在查询中的用途,无论是在添加还是编辑块中。sqlAction
提前致谢。
抛出错误:
System.Data.SqlClient.SqlException:“'11' 附近的语法不正确。
文本可视化工具显示:
Insert into Creditors
Values ('asdf', 'asdf', 'asdf', 'asdf', 'sadf', 'asdf', 'Australia', '231234', 13/10/2023 11:26:53 AM, 'Admin', 1)
代码如下:
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
'Save addition/Changes
'Insert/Edit A Record
'Dim i As Integer
Dim I1 As String = TextBox1.Text
Dim I2 As String = TextBox2.Text
Dim I3 As String = TextBox3.Text
Dim I4 As String = TextBox4.Text
Dim I5 As String = TextBox5.Text
Dim I6 As String = TextBox6.Text
Dim I7 As String = TextBox7.Text
Dim I8 As String = TextBox9.Text
Dim I9 As Date = Now()
Dim I10 As String = strUserName
Dim I11 As String = CheckBox1.Enabled
If CheckBox1.Checked = True Then
I11 = 1
Else
I11 = 0
End If
Dim pid As Integer = TextBox8.Text
'Stop
If con.State = ConnectionState.Open Then con.Close()
If IsAdding = True Then
'Stop
con.Open()
'Insert line into Creditors
sqlAction = "Insert into Creditors Values ('" & I1 &
"','" & I2 & "', '" & I3 &
"', '" & I4 & "', '" & I5 & "', '" & I6 &
"','" & I7 & "','" & I8 & "', " & I9 & ", '" &
I10 & "', " & I11 & ")"
sqlCmd = New SqlCommand(sqlAction, con)
sqlCmd.ExecuteNonQuery()
'MessageBox.Show("Sucessful")
Call DefaultButtons()
' Stop
LoadData(0)
Else
' Stop
'Edit Existing Record
sqlAction = "Update Creditors Set CreditorName = '" & I1 &
"', Addr1 = '" & I2 & "', Addr2 = '" & I3 &
"', City = '" & I4 & "', State = '" & I5 &
"', PostCode = '" & I6 & "', Country ='" & I7 &
"', ContactNbr = '" & I8 &
"',DateAdded = " & I9 & ", AddedBy = '" & I10 & "', IsActive = " & I11 &
" where CreditorID = " & pid & ""
con.Open()
sqlCmd = New SqlCommand(sqlAction, con)
sqlCmd.ExecuteNonQuery()
LoadData(0)
'MessageBox.Show("Sucessful")
End If
con.Close()
Call TextBoxDisabled()
IsAdding = False
IsEditing = False
End Sub
表结构:
CreditorId int False
CreditorName nvarchar(50) False
Addr1 nvarchar(50) True
Addr2 nvarchar(50) True
City nvarchar(50) True
State nvarchar(50) True
PostCode nvarchar(50) True
Country nvarchar(50) True
ContactNbr nvarchar(50) True
DateAdded date False
AddedBy nvarchar(50) False
IsActive bit False
答:
1赞
jmcilhinney
10/13/2023
#1
这个问题不是由拼写错误引起的,而是由缺乏 SQL 语法知识引起的,因此将其作为拼写错误关闭将是一种伤害。如第一条评论中所建议的,导致您报告的错误消息的直接问题是您没有将日期/时间文字放在单引号中:
, '2023-10-13 11:26:53 AM',
还要注意首选的、明确的日期格式。还有许多其他方法可以改进代码,但这将解决特定的语法错误。
评论