强类型数据集 [英] strongly typed dataset

查看:100
本文介绍了强类型数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
强类型的数据集"正在使用具有参数的存储过程,如何在运行时将参数值传递给它.
Thanks

Hello,
"strongly typed DataSet" is using a stored procedure that has a parameter, how do i pass parameter value to it at run time.
thanks

推荐答案

与您对任何SQL查询所做的相同.例如, http://msdn.microsoft.com/en-us/library/yy6y35y8(v = vs.71).aspx [ ^ ]
Same as you do for any SQL query. For example, http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.71).aspx[^]


使用带有参数的存储过程的表适配器将具有带有附加参数的方法.在强类型数据集中使用存储过程时,Visual Studio将自动创建它们.

例如,当您使用存储过程返回按年龄选择的人员记录表时(您的存储过程具有2个参数MinimumAge和MaximumAge).生成的Fill和GetData方法将具有2个(附加)参数:MinimumAge作为Int32,MaximumAge作为Int32.您可以使用以下代码来调用它们:

The tableadapter using the stored procedure with the parameter will have methods with additional parameters. Visual Studio will create them automatically when using stored procedures in strongly typed datasets.

For example when you use the stored procedure to return a table of person records selected by age (your stored procedure has 2 parameters MinimumAge and MaximumAge). The generated Fill and GetData methods will have 2 (additional) parameters: MinimumAge as Int32, MaximumAge as Int32. You could call them with the following code:

Dim table as MyDataSet.PersonTable
Dim minimumAge as Int32 = 24
Dim maximumAge as Int32 = 40

Using ta as MyDataSetTableAdapters.PersonTableAdapter = _ 
     new MyDataSetTableAdapters.PersonTableAdapter()
  table = ta.GetData(minimumAge, maximumAge)
End Usingl



当您的存储过程仅返回标量值或根本不返回任何值时,将使用相同的原理.例如,当您的存储过程返回年龄范围内的人数时,如果在de QueriesTableAdapter中生成了一个方法.



The same principle will be used when your stored procedure only returns a scalar value or no value at all. For instance when your stored procedure returns the number of persons within a age range, if will generated a method in de QueriesTableAdapter.

Dim minimumAge as Int32 = 24
Dim maximumAge as Int32 = 40
Dim numberOfPersonWithinRage as Int32

Using ta as MyDataSetTableAdapters.QueriesTableAdapter = _ 
     new MyDataSetTableAdapters.QueriesTableAdapter()
  numberOfPersonWithinRange = ta.CountPersonsByAge(minimumAge, maximumAge)
End Using



当您在强类型数据集中使用带有参数的SQL语句时,将应用相同的逻辑.



When you use SQL statements with parameters in your strong typed datasets, the same logic will apply.


这篇关于强类型数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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