我正在为我们公司开发一个网络地图应用程序内部网。我正在地图上创建一个“添加多边形”功能。我使用 AspMap、VB.NET 和 SQL Server。当用户单击按钮以从 Web 表单输入数据属性添加新记录时,错误Incorrect syntax near '?' 发生。
我的代码是:
Private Sub AddNewShape(ByVal checklist_id As String, ByVal type As String, ByVal shape As AspMap.Shape, ByVal address_area As String, ByVal dmz As String, ByVal customerid As String, ByVal source As String, ByVal area As String, ByVal instalatur As String, ByVal developer As String, ByVal data_received As DateTime, ByVal doc_data As DateTime, ByVal datereport As DateTime, ByVal remark As String)
Dim tableName As String
Select Case shape.ShapeType
Case AspMap.ShapeType.Line
tableName = "lines"
Case AspMap.ShapeType.Polygon
tableName = "sambungan_baru"
Case Else
Return
End Select
Dim conn As SqlConnection = GetDbConnection()
Dim sql As String = "INSERT INTO " & tableName & " (CHECKLIST_ID, TYPE, SHAPEDATA, ADDRESS_AREA, DMZ, CUSTOMERID, SOURCE, AREA, INSTALATUR, DEVELOPER, DATA_RECEIVED, DOC_DATA, DATA_SENT, REMARK) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
cmd.Parameters.AddWithValue("CHECKLIST_ID", checklist_id)
cmd.Parameters.AddWithValue("TYPE", type)
cmd.Parameters.AddWithValue("SHAPEDATA", shape.ShapeData)
cmd.Parameters.AddWithValue("ADDRESS_AREA", address_area)
cmd.Parameters.AddWithValue("DMZ", dmz)
cmd.Parameters.AddWithValue("CUSTOMERID", customerid)
cmd.Parameters.AddWithValue("SOURCE", source)
cmd.Parameters.AddWithValue("AREA", area)
cmd.Parameters.AddWithValue("INSTALATUR", instalatur)
cmd.Parameters.AddWithValue("DEVELOPER", developer)
cmd.Parameters.AddWithValue("DATA_RECEIVED", data_received)
cmd.Parameters.AddWithValue("DOC_DATA", doc_data)
cmd.Parameters.AddWithValue("DATA_SENT", datereport)
cmd.Parameters.AddWithValue("REMARK", remark)
cmd.ExecuteNonQuery()
conn.Close()
ReloadShapesDatabase()
End Sub
我改变了这个:
Dim sql As String = "INSERT INTO " & tableName & " (CHECKLIST_ID, TYPE, SHAPEDATA, ADDRESS_AREA, DMZ, CUSTOMERID, SOURCE, AREA, INSTALATUR, DEVELOPER, DATA_RECEIVED, DOC_DATA, DATA_SENT, REMARK) VALUES *(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
对此:
Dim sql As String = "INSERT INTO " & tableName & " (CHECKLIST_ID, TYPE, SHAPEDATA, ADDRESS_AREA, MZ, CUSTOMERID, SOURCE, AREA, INSTALATUR, DEVELOPER, DATA_RECEIVED, DOC_DATA, DATA_SENT, REMARK)(@checklist_id, @type, @shapedata, @address_area, @dmz, @conection, @source, @area, @instalatur, @developer, @data_received, @doc_data, data_sent, @remark)"
我遇到了警告:必须声明标量变量“@conection”。谁能帮我?