开发者

C# - Multiple queries DataSet

I want to create a DataSet with multiple queries. Then add the rows that the dataset returns to a listbox. This is what I have so far. My SqlCommand contains multiple queries, I want to add each value from the query to the dataset and then create a foreach statement to get all the rows from the dataset into a listbox

        SqlConnection con = new SqlConnection(connection);
        SqlCommand command = new SqlCommand("select ProductID AS开发者_JAVA技巧 ProductID from Products; Select CategoryName AS CategoryName from Categories; Select count(*) AS Total from Products", con);

        SqlDataAdapter sda = new SqlDataAdapter(command);

        DataSet set = new DataSet();           

        sda.Fill(set);

Enyone has eny idéa how I could do that? Many thnx in advance.


As I see it you're making a list box of 3 very different datas, some product IDs, some category names and a count of products. Its a little confusing to me. However.

If for example you had wanted to have products and categories in the same listbox, you could have done

    select productname as dataname from products 
union 
select categoryname as dataname from categories
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜