用的是oledb连接. 创建表成功了,但是字段长度不对.
如下:
private System.Data.OleDb.OleDbConnection getDBaseConnection(string directoryPath)
{
if (!System.IO.Directory.Exists(directoryPath))
{
throw new Exception("指定的路径不存在", new Exception());
}
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + directoryPath + " ;Extended Properties=dBASE IV;User Id=;Password=;"; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString); return conn; }private void createTable()
{
string fileName=@"D:\dataBase\waterCard.dbf";
OleDbConnection conn = GetDBaseConnection(new FileInfo(fileName).DirectoryName);
createTableSql = @"create table D:\dataBase\watercard.dbf (custId NUMERIC(11) ,custNo NUMERIC(7,0) ,ajustQut NUMERIC(9,2))";
OleDbCommand oleCmd = new OleDbCommand(createTableSql, conn); try
{
conn.Open();
oleCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
程序运行正常,但是表创建后字段长度并非create table 语句中制定的长度
,而是都变成了 (20,5);
我调试了好长时间了,其他数据类型如DATE,LOGICAL,Character都没问题,就是NUMERIC字段类型不行.
如下:
private System.Data.OleDb.OleDbConnection getDBaseConnection(string directoryPath)
{
if (!System.IO.Directory.Exists(directoryPath))
{
throw new Exception("指定的路径不存在", new Exception());
}
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + directoryPath + " ;Extended Properties=dBASE IV;User Id=;Password=;"; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString); return conn; }private void createTable()
{
string fileName=@"D:\dataBase\waterCard.dbf";
OleDbConnection conn = GetDBaseConnection(new FileInfo(fileName).DirectoryName);
createTableSql = @"create table D:\dataBase\watercard.dbf (custId NUMERIC(11) ,custNo NUMERIC(7,0) ,ajustQut NUMERIC(9,2))";
OleDbCommand oleCmd = new OleDbCommand(createTableSql, conn); try
{
conn.Open();
oleCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
程序运行正常,但是表创建后字段长度并非create table 语句中制定的长度
,而是都变成了 (20,5);
我调试了好长时间了,其他数据类型如DATE,LOGICAL,Character都没问题,就是NUMERIC字段类型不行.
解决方案 »
- Oracle 动态sql 参数问题
- C#中引入了命名空间,可是其中的关键字点不出来
- 怎么在mdi窗体中从主窗体或者一个子窗体给其他一个或者几个已经显示了的窗体传参数?
- OCR识别的问题!
- dataGridView设置那里才能使得增加一条数据后 高度自动增加
- C#(windows control library)生成的DLL,为什么不能被asp.net(C#)调用?
- winform中的datagrid 如何设定某些特定的单元格不能编辑,可以具体定位到某一行某一列
- 用.net remoting访问驻留在iis中的程序时的问题
- 怎么生成html新闻?
- 如何将 鼠标的滚轮事件屏蔽掉?
- 编辑 dataGridview一个单元格,当我改变它的值时,应该会触发什么事件?
- TCP/IP通讯模式和实现问题,急用,谢谢
谢谢支持。
是 dbase IV 数据库.有NUMERIC,没有interger 所以才会需要custId NUMERIC(11),这样的。
变通的方法也有,但是我搞不懂为什么会出现这种情况啊。
如;
https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=811137&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=137286&SiteID=1
但是
在http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=364457&SiteID=1 上,微软的一个mvp 说odbc dbase 同样存在这个问题,那是因为ms odbc dbase不支持。建议使用oledb vfp.呵呵,说回来了,其实我原来就是用的这个,
string connectionString = "Provider=vfpoledb.1;Data Source=" + directoryPath + " ;Collating Sequence=MACHINE";
只不过后来发现生成的不是dbase iv 格式,而是visual foxpro 格式,因为我的掌上电脑必须要求xbase 或 foxpro 格式,但是现在还是要使用它了,只不过在遇到需要创建interger等时,类型判断上尽量向dbase 上靠拢,如n(x,0)就相当于interger,就可以了。算是揭帖了。