在带有Delphi 2010的SQL Server中分配表类型输入参数 [英] Assign Table-Type input paramater in SQL Server with Delphi 2010

查看:80
本文介绍了在带有Delphi 2010的SQL Server中分配表类型输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将记录从Paradox-7表复制到SQL Server2008.

我已经在SQL Server 2008中使用表类型输入参数创建了一个存储过程.

使用Delphi 2010,如何将Paradox DB表的记录发送到此存储过程?

这些表已存在于SQL Server中.

我试过了,但是它给出了关于参数类型的错误:

I need to copy records from Paradox-7 tables to SQL Server 2008.

I have created a stored procedure in SQL Server 2008 with a table-type input parameter.

Using Delphi 2010, how can I send a Paradox DB table''s records to this stored procedure?

The tables already exist in SQL Server.

I tried this, but it gives an error regarding the paramater type:

VAImpTable.Open;   // this is a BDE TTable component
// spBatchInsert is a dbExpress TSQLStoredProc component
spBatchInsert.ParamByName('@input_table').AsDataSet := VAImpTable;
try
  spBatchInsert.ExecProc;
except on e: Exception do
  ShowMessage(e.Message);
end;
VAImpTable.Close;

推荐答案



我知道这可能为时已晚,但是由于尚未收到任何回应,因此不妨试一试.我对此可能是错的,但不应使代码看起来像这样:

Hi,

I know this is probably a bit too late, but since there haven''t been any responses, I might as well give this a shot. I may be wrong regarding this, but shouldn''t that code looks something like:

VAImpTable.Open;
VAImpTable.First;
VAImpTable.FetchAll; // Make sure we have ALL the data for the migrate
VAImpTable.First; // Just to make sure that we are back at the first record
spBatchInsert.ParamByName('@input_table').DataType := ftDataSet;
spBatchInsert.ParamByName('@input_table').Direction := pdInput;
spBatchInsert.ParamByName('@input_table').Value := VAImpTable;
try
  spBatchInsert.ExecProc;
except on e: Exception do
  ShowMessage(e.Message);
end;
VAImpTable.Close;


我知道" AsDataSet "很简单,但是我个人更喜欢显式设置某些属性,尤其是诸如数据源参数输入之类的内容.

话虽这么说,但我在许多月前就遇到过将应用程序的数据源从一个提供程序转换为另一个提供程序的问题.我刚刚结束编写了一个通用类,该类将物理地将数据从一个移动到另一个.

在那个阶段,它被证明是更加可靠的,因为我可以编写后代类,这些后代类将特定于某些类型的(提供者)数据库类型,因为某些(字段)定义在两者之间无法正确移植. br/>
希望有帮助,
格伦


I know the "AsDataSet" is short-hand, but personally I prefer setting certain properties, especially things like data source parameter inputs, explicitly.

Having said that though, I had issues many moons ago converting the data source of an application from one provider to another. I just ended up writing a generic class that would physically move the data from the one to the other.

At that stage, it proved to be much more reliable, because I could then write descendant classes which would then be specific to certain types of (provider) database types as some (field) definitions didn''t port properly between the two.

Hope that helps,
Glen


这篇关于在带有Delphi 2010的SQL Server中分配表类型输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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