如何创建Delphi 4结构将XLS中的列名映射到SQL中的列名 [英] how to create Delphi 4 structure to map column names in XLS to column names in SQL

查看:96
本文介绍了如何创建Delphi 4结构将XLS中的列名映射到SQL中的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EXCEL sheet.it有各种表单字段,命名为

I have an EXCEL sheet.it has various form-fields that are named as

 "smrBgm133GallonsGross/ smrBgm167GallonsGross "  

 "smrEgm133GallonsGross/ smrEgm167GallonsGross "

我添加到XCEL表格2个新表单字段名为

smrBgm167GrosGalnsDA / smrEgm167GrosGalnsDA

I added to the XCEL sheets 2 new form fields named
smrBgm167GrosGalnsDA/smrEgm167GrosGalnsDA

我在EXCEL中制作的上述补充说明应该被命名为

The above additons I made in EXCEL should ACTUALLy be named as

`smrBgm229GallonsGross/smrEgm229GallonsGross` because. This is a  MUST  for the Delphi application to function properly.

这个Delphi-4应用程序提取出来,并将数据与数据库串联起来。

This Delphi-4 application extracts , and vewrifys the form DATA in tandem with the DB.

我的Delphi-4应用程序工作(检查/插入/检索),以便目前几个月开始加奶牛奶bgm229等于上个月结束牛奶加仑egm229,以及然后如果它们不同,则抛出异常。

My Delphi-4 application works (checks/inserts/retrieves) so that current months beginning gallon of milk "bgm229" is equal to last months ending gallon of milk "egm229" , and then throw an exception if they are different.

Excel表: - Bgm167GrosGalnsDA / Egm160GrosGalnsDA
Delphi代码(DB输入/ DB输出/验证): - bgm229 / egm229
SQL 2005 DB: - bgm167DA / egm167DA

实际上,我添加的列应该是命名为asasmrEgm133GallonsGross / smrEgm167GallonsGross...我搞砸命名他们,他们在生产现在....

Excel sheets:- Bgm167GrosGalnsDA/ Egm160GrosGalnsDA Delphi Code (DB- input/ DB- output/validation):- bgm229/ egm229 SQL 2005 DB:- bgm167DA/ egm167DA
Actually the columns I ADDED should have been named asa "smrEgm133GallonsGross/ smrEgm167GallonsGross "...I messed up in naming them and they are on the production now....

在Delphi程序中,对于初始库存,代码为

In the Delphi procedure,for the beginning inventory, the code it is

  ExtractFormBgmInfo(smrMilkAvMilk,  'smrBgm133');
  ExtractFormBgmInfo(smrMilkDe,           'smrBgm167');

为了结束库存,代码为

  ExtractFormEgmInfo(smrMilkAvMilk,  'smrEgm133');
  ExtractFormEgmInfo(smrMilkDe,           'smrEgm167');

我将smrBgm229GrosGalns / smrEgm229GrosGalns添加到列表
但问题是他们在EXCEL表中被错误地命名为smrBgm167GrosGalnsDA / smrEgm167GrosGalnsDA,而它们将被命名为smrBgm229 /'smrEgm229(如在Delphi代码中的情况)。因此。我添加了以上

I am adding "smrBgm229GrosGalns/smrEgm229GrosGalns" to the list But the issue is that they are named erroneously as "smrBgm167GrosGalnsDA/ smrEgm167GrosGalnsDA" IN THE EXCEL sheets, while they are to be named as 'smrBgm229/'smrEgm229''(as is the case in the Delphi code). Hence. I added ...to the above

  ExtractFormBgmInfo(smrMilkAvMilk,    'smrBgm133');
  ExtractFormBgmInfo(smrMilkDe,           'smrBgm167');
  ExtractFormBgmInfo(smrMilkDyedDe,       'smrBgm229'); 

  ExtractFormEgmInfo(smrMilkAvMilk,      'smrEgm133');
  ExtractFormEgmInfo(smrMilkDe,           'smrEgm167');
  ExtractFormEgmInfo(smrMilkDyedDe,       'smrEgm229');

这会引发错误,因为在EXCEL表格中没有定义smrBgm229GallonsGross / smrEgm229GallonsGross strong>。问题是如何将smrBgm167GrosGalnsDA从Excel表格转换为smrBgm229GallonsGross,然后使我的ExtractForm语句正确?

This throws an error , as smrBgm229GallonsGross /smrEgm229GallonsGross are not defined in the EXCEL sheets .So the issue is how do I convert "smrBgm167GrosGalnsDA" from Excel sheets into "smrBgm229GallonsGross" and then make my "ExtractForm" statement correct?

请帮助今天安排一个版本,并与我的超级设备进行讨论。

Please help there is an release scheduled today and got to discuss this with my superirors

推荐答案

你想做什么将一个字符串映射到另一个。您可以使用一个简单的字符串列表。

What you want to do is map one string to another. You can use a simple string list for that.

// Declare the variable somewhere, such as at unit scope or as a field
// of your form class
var
  ColumnNameMap: TStrings;







// Somewhere else, such as unit initialization or a class constructor,
// initialize the data structure with the column-name mappings.    
ColumnNameMap := TStringList.Create;
ColumnNameMap.Values['Bgm167 GrosGalns DA'] := 'bgm229/ egm229';







// In yet a third place in your code, use something like this to map
// the column name in your input to the real column name in your output.
i := ColumnNameMap.IndexOfName(ColumnName);
if i >= 0 then
  RealColumnName := ColumnNameMap.Values[ColumnName]
else
  RealColumnName := ColumnName;

更新版本的Delphi具有通用的 TDictionary 类。使用 TDictionary< string,string> TStrings 解决方案如果任何列名称中的列名称可以具有等号,我上面概述的将会有问题,但您可以通过更改 NameValueSeparator 属性。

Later versions of Delphi have the generic TDictionary class. Use TDictionary<string, string>. The TStrings solution I outlined above will have problems if any of the column names can have equals signs in them, but you can mitigate that by changing the NameValueSeparator property.

var
  ColumnNameMap: TDictionary<string, string>;







ColumnNameMap := TDictionary<string, string>.Create;
ColumnNameMap.Add('Bgm167 GrosGalns DA', 'bgm229/ egm229');







if not ColumnNameMap.TryGetValue(ColumnName, RealColumnName) then
  RealColumnName := ColumnName;

这篇关于如何创建Delphi 4结构将XLS中的列名映射到SQL中的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆