多值参数传入数据集以填充 [英] Multiple value parameter passing in a dataset to fill

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

问题描述


我为此一直苦苦挣扎很长时间,通常用户可以通过复选框选择多个选择,然后根据这些复选框,我们从(23,56,78)中的class_id类中选择类似Select *的查询参数.多个选择将在上述语句之类的查询中传递.我真的无法完全通过"23,56,78.

我已经在设计器中编辑了我的数据集,并更改了它的字符串,使其类似于从*中的class_id(& paramstr&")中选择*,并在每次调用要填充的数据集时将paramstr设置为23,56,78 .但是问题在于,只要在设计器形式的开放数据集中,它就会重置为我的原始查询,从(23,56,78)中class_id的类中选择*当我遍历它时,我发现有一个xml格式的xsd文件会更新数据集从这里开始但是我不知道如何更改其命令文本以接受变量.

我在这里想要两个解决方案:
一个.我在做什么对不对?如果不是,传递多个值的正确方法是什么
b.我如何设置变量,以便它对我来说永久有效.

我正在使用vb.net 2005 winforms和访问数据库
致以最诚挚的问候
Jay Khatri

Hi
I''ve been struggling for a long time about this, normally user have a multiple choices which is select by checkboxes and based upon these checkboxes we make the query parameter like Select * from classes where class_id in (23,56,78) The multiple choices will be passed in a query like the above Statement. I am really unable to pass "23,56,78 altogether.

I have edited my dataset in designer and changed its string to like this "Select * from classes where class_id in (" & paramstr & ")" and set the paramstr = 23,56,78 whenever I call the dataset to be filled. But problem is whenever in open dataset in designer form it gets reset to my original query Select * from classes where class_id in (23,56,78) When I go through it I found there is an xsd file in xml format it updates the dataset to it original from here. But I dont have any idea how to change its commandtext to accept a variable.

I want two solutions here:
a. Whether what I am doing is right or not? if not what is the right way to pass multiple values
b. How can I set the variable in so that it works permanent for me.

I am using vb.net 2005 winforms and access database
Thanks & Best Regards
Jay Khatri

推荐答案

看看传递数组或将DataTable放入存储过程中 [ ^ ]的一些想法.

代码是C#,但希望您能够遵循这些原则.
Take a look at Passing an array or DataTable into a stored procedure[^] for some ideas.

The code is C# but hopefully you will be able to follow the principles.


我唯一想到的方法是分阶段构建SQL Query.

像执行操作一样,将用户选择的内容放入数组(paramArray).

将查询的字符串变量(queryString)设置为"SELECT * FROM classes WHERE class-id =" + paramArray [0] .ToString()

然后遍历数组,并为每个条目(在第一个条目之后)添加 **

The only way I can think of to do this is to build your SQL Query in stages.

Get the users selections into an array (paramArray), as you are doing.

Set a string variable (queryString) for your Query to "SELECT * FROM classes WHERE class-id = " + paramArray[0].ToString()

then loop through your array and for each entry (after the first) add**

queryString = querystring + " OR class-id = " + paramArray[x].ToString()



如果您熟悉StringBuilder,请使用它代替String,如果不熟悉,请先使用它,然后研究StringBuilder并转换您的代码以使用它.

** 请检查Access SQL语法,因为我正在脑海中进行操作.

祝你好运! :)



If you are familiar with StringBuilder then use that instead of a String, if not then get it working first then study StringBuilder and convert your code to use it.

**Check the Access SQL syntax for this, as I am doing it off the top of my head.

Good luck! :)


我完全理解您的观点,是的,我在很多地方都使用StringBuilder.但是我说过我使用数据集设计器设计了数据集,即使查询是如此复杂,让我看看如何将文本添加到条件中.您还知道ms-access中sql查询的局限性.

我将尝试使用循环和oring.我想问一下这个技巧是否仍然有机会更改由Dataset Designer开发的xml格式的代码.并将变量传递给它,这样我的代码就不会改变.

非常感谢您的支持.

杰伊·哈特里(Jay Khatri)
I fully understood your view, and yes I use StringBuilder at many places. But I said I designed the dataset using Dataset Designer and even the query is so complicated, let see how I will add a text piece to or condition. You are also aware about the limitation of sql query in ms-access.

I will try to use the loop and oring. I would like to ask if it is still a chance for this trick to alter the code that has been developed by Dataset Designer in xml format. and passing variable to it so that my code not get altered.

Thank you very much for all of your support.

Jay Khatri


这篇关于多值参数传入数据集以填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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