尝试执行此查询时出现语法错误:
USE MainDB1
IF EXISTS (SELECT * FROM sysobjects WHERE Name = 'logging' AND TYPE = 'u')
BEGIN
DROP TABLE MainDB1.dbo.logging
END
Create Table logging (TIME NVarChar(20) NOT NULL,1-Bit_Boolean NVarChar(20) NOT NULL,1-Bit_Boolean NVarChar(20) NOT NULL,1-Bit_Boolean NVarChar(20) NOT NULL,1-Bit_Boolean NVarChar(20) NOT NULL,64-Bit_IEEE_floating_point NVarChar(20) NOT NULL,64-Bit_IEEE_floating_point NVarChar(20) NOT NULL,64-Bit_IEEE_floating_point NVarChar(20) NOT NULL,64-Bit_IEEE_floating_point NVarChar(20) NOT NULL,64-Bit_IEEE_floating_point_array NVarChar(20) NOT NULL,32-Bit_unsigned_integer NVarChar(20) NOT NULL,32-Bit_unsigned_integer NVarChar(20) NOT NULL,32-Bit_unsigned_integer NVarChar(20) NOT NULL,32-Bit_unsigned_integer NVarChar(20) NOT NULL,32-Bit_unsigned_integer_array NVarChar(20) NOT NULL,32-Bit_IEEE_floating_point NVarChar(20) NOT NULL,32-Bit_IEEE_floating_point NVarChar(20) NOT NULL,32-Bit_IEEE_floating_point NVarChar(20) NOT NULL,32-Bit_IEEE_floating_point NVarChar(20) NOT NULL,32-Bit_IEEE_floating_point_array NVarChar(20) NOT NULL,32-Bit_signed_integer NVarChar(20) NOT NULL,32-Bit_signed_integer NVarChar(20) NOT NULL,32-Bit_signed_integer NVarChar(20) NOT NULL,32-Bit_signed_integer NVarChar(20) NOT NULL,32-Bit_signed_integer_array NVarChar(20) NOT NULL,16-Bit_signed_integer NVarChar(20) NOT NULL,16-Bit_signed_integer NVarChar(20) NOT NULL,16-Bit_signed_integer NVarChar(20) NOT NULL,16-Bit_signed_integer NVarChar(20) NOT NULL,16-Bit_signed_integer_array NVarChar(20) NOT NULL,16-Bit_unsigned_integer NVarChar(20) NOT NULL,16-Bit_unsigned_integer NVarChar(20) NOT NULL,16-Bit_unsigned_integer NVarChar(20) NOT NULL,16-Bit_unsigned_integer NVarChar(20) NOT NULL,16-Bit_unsigned_integer_array NVarChar(20) NOT NULL)
语法错误发生在第 6 行的第一个 1-Bit_Boolean 处。查询保存在字符串中,稍后执行。
VB.NET 代码:
Dim sqlcreatetable As String = _
"USE MainDB1" & vbCrLf & _
"IF EXISTS (SELECT * FROM sysobjects WHERE Name = 'logging' AND TYPE = 'u')" & vbCrLf & _
"BEGIN" & vbCrLf & _
"DROP TABLE MainDB1.dbo.logging" & vbCrLf & _
"END" & vbCrLf & _
"Create Table logging (TIME NVarChar(20) NOT NULL,"
For i As Integer = 1 To aantaltags - 1
If (i = aantaltags - 1) Then
sqlcreatetable += csvsql(i) & " NVarChar(20) NOT NULL)"
Else
sqlcreatetable += csvsql(i) & " NVarChar(20) NOT NULL,"
End If
Next
Dim dbConnection As New SqlCommand(sqlcreatetable, connection)
connection.Open()
dbConnection.ExecuteNonQuery()
connection.Close()