如何找出 SQL Server CE 列的长度
我使用 SQL Server CE 创建了一个表,如下所示:
SqlCeCommand createTableCmd = new SqlCeCommand();
createTableCmd.CommandText = "Create table docEntry (id nvarchar (70) not null PRIMARY KEY, "
+ "parent nvarchar(70), "
+ "lmt bigint not null, "
+ "fileName nvarchar(70) not null)";
表名称为 docEntry,我需要查找的列宽为 fileName 列。
目的是检测列宽是否为70,如果是,我需要将其扩展为其他尺寸,否则保留它。
我尝试了
SELECT COL_LENGTH(docEntry, fileName)
一下,导致异常:
SqlCeException 被捕获:
列名称无效。 [ 节点名称(如果有) = ,列名称 = docEntry ]
我不知道为什么......
有人知道吗?
I created a table using SQL Server CE like this:
SqlCeCommand createTableCmd = new SqlCeCommand();
createTableCmd.CommandText = "Create table docEntry (id nvarchar (70) not null PRIMARY KEY, "
+ "parent nvarchar(70), "
+ "lmt bigint not null, "
+ "fileName nvarchar(70) not null)";
Table name is docEntry
, and the column width I need to find out is fileName column.
The purpose is to detect if the column width is 70, if yes, I need to expand it to other size, else leave it.
I tried
SELECT COL_LENGTH(docEntry, fileName)
it caused exception:
SqlCeException was caught:
The column name is not valid. [ Node name (if any) = ,Column name = docEntry ]
I don't know why...
Anyone knows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
认为你将不得不做很长的路:
Think you will have to do it the long way:
<罢工>
除了来自 @HadleyHope 的提供者特定解决方案之外,还有一个适用于所有数据库的解决方案(至少我通过 OleDB 尝试过 mssql2005、oracle10、SQlite3 和 MsAccess。我的机器上没有 sqlce 需要验证):
DbConnection.GetSchema()
此代码适用于 MsSql。
您必须替换
con = new SqlConnection()
如果 SqlCeConnection 不支持“AllColumns”,请调用 con.GetSchema() 来获取支持的属性列表。
有关详细信息,请参阅 GetSchema - DbConnection.GetSchema ADO.NET 2.0 - 从数据库连接和msdn DbConnection.GetSchema()
beside providerspecific solution from @HadleyHope there is a solution that works for all Dabases (at least i tried with mssql2005, oracle10, SQlite3 and MsAccess via OleDB. i have no sqlce on my machine to verify):
DbConnection.GetSchema()
This codes works for MsSql.
You have to replace
con = new SqlConnection()
if "AllColumns" is not supported by SqlCeConnection call
con.GetSchema()
to get a list of supported properties.For more info see GetSchema - DbConnection.GetSchema in ADO.NET 2.0 - Retrieve Databases Tables Columns Views etc. from Database Connection and msdn DbConnection.GetSchema()
表名和列名需要用引号引起来:
Table and column names need to be in quotes: