我是数据库初学者,我在创建表时正在AUTOINCREMENT
,但发生了以下错误:
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ','.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolea
n breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception
, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObj
ect stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,
TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,
Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSou
rce`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean
asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at KellenTechnology.Program.Main(String[] args) in c:\Users\Mohit\Documents\V
isual Studio 2013\Projects\KellenTechnology\KellenTechnology\Program.cs:line 39
ClientConnectionId:1629d6a5-8e66-445b-99b1-b009103d0343
♂Data base Connection Closed.
我的代码是:
string sqlStatement = "CREATE TABLE " + Table1Name + ""
+ "(network_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "network_full_name VARCHAR(50) NOT NULL)";
有人可以让我知道它有什么问题吗?我还找到not null identity(1, 1)
而不是autoincrement
,但这两者有何不同?
答案 0 :(得分:3)
MS SQL-Server相当于自动递增称为identity
:
string sqlStatement = "CREATE TABLE " + Table1Name +
+ "(network_id INTEGER NOT NULL IDENTITY(1,1) PRIMARY KEY,"
+ "network_full_name VARCHAR(50) NOT NULL)";
答案 1 :(得分:1)
尝试使用SQL Server,因为错误是Sql Server的错误
string sqlStatement = "CREATE TABLE " + Table1Name + ""
+ " (network_id INTEGER identity(1,1) PRIMARY KEY,"
+ "network_full_name VARCHAR(50) NOT NULL)";
<强> BEWARE OF SQL INJECTION 强>