你好; 在一个程序中,我需要在运行时创建一个表并将其添加到(访问类型的)数据库中.该表具有一个数字类型的字段,称为年龄.为了验证此字段中写入的所有数据,我在以下代码中使用了check命令.我想知道为什么它会在运行时引发错误,说明字段定义中存在语法错误.你能帮我吗? 非常感谢您
Hello; In a program I need to create and add a Table to a database (of Access type) at run time. The table has a field of Number type called Age. To validate all data written in this field, I used check command in the following code. I wonder why it raises an error at runtime saying that there is Syntax error in field definition. Could you please help me? Thank you very much
using System.Data.OleDb; ... OleDbConnection myConnection = new OleDbConnection(); myConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + @"E:\MyDataBase.accdb"; OleDbCommand myCommand = new OleDbCommand(); myCommand.Connection = myConnection; myCommand.CommandText = "CREATE TABLE Family" + " (" + " ID int IDENTITY(1,1) PRIMARY KEY," + " FName Char(10)," + " LName Char(10)," + " Age int NOT NULL CHECK (Age <= 100),"+ " )"; myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close();推荐答案
在检查(Age< = 100)"之前加上," 您仍然缺少一个逗号... put the "," before "Check (Age <=100)" you are still missing one comma...... using System.Data.OleDb; ... OleDbConnection myConnection = new OleDbConnection(); myConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + @"E:\MyDataBase.accdb"; OleDbCommand myCommand = new OleDbCommand(); myCommand.Connection = myConnection; myCommand.CommandText = "CREATE TABLE Family" + " (" + " ID int IDENTITY(1,1) PRIMARY KEY," + " FName Char(10)," + " LName Char(10)," + " Age int NOT NULL," + " CHECK (Age <= 100)"+ " )"; myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close();
并尝试阅读这篇文章........ office.microsoft/zh-cn/access-help/access-projects-and-data-access-pages-now-use-ansi-sql-92-syntax-HA001034562.aspx
and try to read this article........ office.microsoft/en-us/access-help/access-projects-and-data-access-pages-now-use-ansi-sql-92-syntax-HA001034562.aspx
亲爱的朋友; 我在年龄段输入了错误的,".我删除了它,但是尽管存在问题. Dear Friends; I misstyped '','' at age line. I deleted it but although the problem exists. " Age int NOT NULL CHECK (Age <= 100),"
已更正为 "Age int NOT NULL CHECK(年龄< = 100)
is corrected to " Age int NOT NULL CHECK (Age <= 100)
" 但问题存在.
" but the problem exists.
更多推荐
检查在运行时创建的表的字段的数据验证
发布评论