如何保留用 C# 创建的 .dbf 表中的列顺序?
我正在尝试使用 Visual C# 创建 .dbf 表,因为我需要它将数据导入到另一个应用程序。为此,我需要列顺序完全正确,否则该应用程序将不接受该表。到目前为止,它运行良好,但最近我必须对表的结构进行一些更改,并且我已将列添加到 CREATE 语句中的确切位置。我遇到的问题是,当我使用 Visual Fox Pro 创建表后打开表时,新列位于表的末尾,而不是我放置它们的位置。
我的代码如下:
#region create dbf file
//create the file again
string strCreate = "CREATE TABLE " + strExportPath + "\\"+fisier+" " +
"(TIPD Numeric(1), "+
" LN Numeric(2), " +
" AN Numeric(4), "+
" DEN_ANG Char(50), " +
" CUI Char(13), " +
" NR_CRT Numeric(6), "+
" TIP_RECTIF Char(1), " +
" NUME_ASIG Char(50), " +
" CNP Char(13), "+
" CNP_COPIL Char(13), "+
" CAS_ASIG Char(2), "+
" ZI_LUCRAT Numeric(2), "+
" TOT_ZI_LUC Numeric(2), "+
" SERIE_CCM Char(5), "+
" NUMAR_CCM Char(10), "+
" SERIE_CCM_ Char(5), "+
" NUMAR_CCM_ Char(10), "+
" DATA_ACORD DATE, " +
" COD_INDEMN Char(2), " +
" ZI_PRE_ANG Numeric(1), "+
" ZI_FN Numeric(2), " +
" ZI_PRE Numeric(2), "+
" LOC_PRES Numeric(2), "+
" SUM_ANG Numeric(18), "+
" FN Numeric(18), " +
" DATA_INC DATE, "+
" DATA_SF DATE, "+
" COD_URG Char(3), " +
" COD_CONTAG Char(2), "+
" BAZA_CALC Numeric(6), "+
" ZI_BZ_CALC Numeric(3), "+
" MZBCI Numeric(8,4), "+
" ME_NR CHAR(10))";
OleDbConnection con = new OleDbConnection(strConn);
try
{
con.Open();
}
catch //(Exception ex)
{
NMsgBox("Err", "", "Renunta");
return;
}
OleDbCommand createCmd = new OleDbCommand(strCreate, con);
try
{
createCmd.ExecuteNonQuery();
}
catch //(Exception ex)
{
NMsgBox("Err "+fisier, "", Renunta");
return;
}
con.Close();
CNP_COPIL、DATA_ACORD 和 LOC_PRES 等列是一些新列,并且始终放在最后,即使我在 Visual Fox Pro 中执行 CREATE COMMAND
我也可以提到我每次都会创建一个空表并填充它与数据,我不做改变表,因为我不需要。每个月都有一张新桌子。
我似乎不明白为什么它将“新列”放在最后,即使该表是一个新表并且我已从该位置删除了所有以前的表
I am trying to create a .dbf table using Visual C# because I need it to import data to another application. For that purpose I need the column order to be exactly right otherwise that application won't accept the table. It's been working fine so far, but recently I had to make some changes to the structure of the table, and I have added the columns in the exact position in the CREATE Statement. The problem that I am getting is that when I open the table after creation with Visual Fox Pro the new columns are at the end of the table, not where I put them.
My code is as follows:
#region create dbf file
//create the file again
string strCreate = "CREATE TABLE " + strExportPath + "\\"+fisier+" " +
"(TIPD Numeric(1), "+
" LN Numeric(2), " +
" AN Numeric(4), "+
" DEN_ANG Char(50), " +
" CUI Char(13), " +
" NR_CRT Numeric(6), "+
" TIP_RECTIF Char(1), " +
" NUME_ASIG Char(50), " +
" CNP Char(13), "+
" CNP_COPIL Char(13), "+
" CAS_ASIG Char(2), "+
" ZI_LUCRAT Numeric(2), "+
" TOT_ZI_LUC Numeric(2), "+
" SERIE_CCM Char(5), "+
" NUMAR_CCM Char(10), "+
" SERIE_CCM_ Char(5), "+
" NUMAR_CCM_ Char(10), "+
" DATA_ACORD DATE, " +
" COD_INDEMN Char(2), " +
" ZI_PRE_ANG Numeric(1), "+
" ZI_FN Numeric(2), " +
" ZI_PRE Numeric(2), "+
" LOC_PRES Numeric(2), "+
" SUM_ANG Numeric(18), "+
" FN Numeric(18), " +
" DATA_INC DATE, "+
" DATA_SF DATE, "+
" COD_URG Char(3), " +
" COD_CONTAG Char(2), "+
" BAZA_CALC Numeric(6), "+
" ZI_BZ_CALC Numeric(3), "+
" MZBCI Numeric(8,4), "+
" ME_NR CHAR(10))";
OleDbConnection con = new OleDbConnection(strConn);
try
{
con.Open();
}
catch //(Exception ex)
{
NMsgBox("Err", "", "Renunta");
return;
}
OleDbCommand createCmd = new OleDbCommand(strCreate, con);
try
{
createCmd.ExecuteNonQuery();
}
catch //(Exception ex)
{
NMsgBox("Err "+fisier, "", Renunta");
return;
}
con.Close();
Columns like CNP_COPIL, DATA_ACORD and LOC_PRES are some of the new column, and are always put last, even if I execute the CREATE COMMAND in Visual Fox Pro
I can also mention that I CREATE an empty table everytime and fill it with data, I don't do alter table, because i don't need to. Every month there's a new table.
And I don't seem to get why it would put "new columns" last, even IF the table is a new one and I have deleted every previous one from that location
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 Foxpro IDE 中更改 Foxpro 表的列顺序。
单击字段左侧的按钮并将其向上或向下拖动到您需要的位置。
编辑:在阅读有关它在老板的计算机上工作的评论后,听起来问题是 Foxuser.dbf 正在记住您上次浏览的列顺序 - 因为列最后不存在时间它只是在最后显示它们,尽管它们实际上在中间。
您使用什么命令来查看计算机上的表格?
You can change the column order of a Foxpro Table within the Foxpro IDE.
Click on the button on left of the field and drag it up or down to where you need it.
EDIT: After reading the comment about it working on your boss's computer it sounds like the problem is that the foxuser.dbf is remembering the column order you browsed with last - since the columns weren't there the last time it just shows them at the end though they are really in the middle.
What exact command are you using to look at the table on your computer?
当表是全新的时,对列进行重新排序当然是毫无意义的。当您查看表结构时,顺序看起来是正确的。
只有一个很好的解释:无论您使用什么程序查看该表,都已经记住了上一次运行的列顺序。并将新列放在最后。这将是一个非常常见和理想的功能,允许用户返回表格的视图,就像她上次查看它时一样。布局数据必须存储在程序的私有数据中,.dbf 文件格式无法存储它。
这只是一个显示伪影,不会以任何方式影响正常操作。
It of course makes zero sense that the columns would be re-ordered when the table is brand new. And that the order looks correct when you look at the table structure.
There's only one good explanation: whatever program you are using to look at the table has memorized the column order from a previous run. And puts the new columns at the end. This would be a very common and desirable feature, allowing the user to get back the view of the table just like it was the last time she looked at it. The layout data has to be stored in private data of the program, the .dbf file format cannot store it.
This is just a display artifact, it cannot affect proper operation in any way.