检查在运行时创建的表的字段的数据验证

编程入门 行业动态 更新时间:2024-10-10 08:19:33
本文介绍了检查在运行时创建的表的字段的数据验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好; 在一个程序中,我需要在运行时创建一个表并将其添加到(访问类型的)数据库中.该表具有一个数字类型的字段,称为年龄.为了验证此字段中写入的所有数据,我在以下代码中使用了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.

更多推荐

检查在运行时创建的表的字段的数据验证

本文发布于:2023-11-30 21:42:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!