[英]What is wrong with the syntax of this SQL statement I am using to create a table?
我一直在运行代码/调试器,甚至设置断点,所以我可以单步执行代码,却无法找到语法错误在哪里,我知道在此C#方法中用于在c树中创建新表的语法错误数据库。
这是代码:
/*
Define() method
where specific data definitions are established also will include the definition of the table
being created as well as defining rows and columns of the table
*/
public static void Define()
{
Console.WriteLine("DEFINE");
try
{
//Creation of the table with the specified data types and the column Names
Console.WriteLine("\tCreating table...");
cmd.CommandText = "CREATE TABLE testData (" +
"Trackingid VARCHAR(35)," +
"dates DATETIME," +
"Name_Of_Recipient VARCHAR(35)," +
"addresss VARCHAR(35)," +
"address2 VARCHAR(31)," +
"City VARCHAR(34)," +
"Town VARCHAR(23)," +
"states VARCHAR(5)," +
"ZipCode INT )";
cmd.ExecuteNonQuery();
}
catch(CtreeSqlException e)
{
Console.WriteLine(e + " could not define this table");
}
catch(Exception e)
{
Console.WriteLine(e + "Error the table could not be defined");
}
}
就像我在尝试多次遍历代码之前所提到的那样,我假设这可能是我必须有许多列条目吗? 还是严重依赖VARCHAR数据类型?
抛出异常消息:
" Creating table...
Ctree.Data.SqlClient.CtreeSqlException (0x7FFFB1DD): Syntax error ---> Ctree.SqlClient.Common.FcSqlException: Syntax error
at Ctree.SqlClient.FcSqlXApi.SQLExec(FcStatement stmt, Int32 InStatementType, FcSqlDA ida, FcSqlDA oda, FcSqlCA sqlca)
at Ctree.SqlClient.FcSqlXApi.Prepare(FcStatement stmt, FcSqlDA input_sqlda, FcSqlDA output_sqlda, Int32 fetchSize)
at Ctree.SqlClient.FcConnection.Prepare(FcStatement statement, FcSqlDA inputDA, FcSqlDA outputDA, Int32 fetchSize)
at Ctree.SqlClient.FcPreparedStatement..ctor(FcConnection connexion, String sql, Int32 fetchSize, Int32 timeout)
at Ctree.Data.SqlClient.CtreeSqlCommand.InternalPrepare(Boolean resultSet)
at Ctree.Data.SqlClient.CtreeSqlCommand.ExecuteNonQuery()
at Ctree.Data.SqlClient.CtreeSqlCommand.ExecuteNonQuery()
at DBbeta.Program.Define() in C:\Users\WVX0DYQ\source\repos\DBbeta\DBbeta\Program.cs:line 76 could not define this table"
首先检查表是否存在。 如果不存在,则创建表。
这个正在运行的示例将您的值并运行
并使用INTEGER not int 参见此数据类型
var commandStr= "CREATE TABLE Customer(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime)";
using (SqlCommand command = new SqlCommand(commandStr, con))
command.ExecuteNonQuery();
查找参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.