Click here to Skip to main content
15,884,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanx guys for the help But now for application I need load more than 2 tables into a single DataSet but please do bare in mind that I am NOT YET Familiar with stored procedures in SQL Server 2008 the code that I am using is as shown below.Please guyz do help me I am still new to VB.NET
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
    Public Sub New()
        InitializeComponent()
        ' connect to my local server, northwind db
        Dim connectionString As String = _
            "server=localhost; " & _
            "Integrated Security=True; " & _
            "database=Northwind"

        Dim commandString As String = _
        "Select CompanyName, ContactName, ContactTitle, " & _
        "Phone, Fax from Customers"

        ' create a data set and fill it
        Dim myDataAdapter As _
        New SqlDataAdapter(commandString, connectionString)
        Dim myDataSet As New DataSet()
        myDataAdapter.Fill(myDataSet, "Customers")

        ' bind the DataSet to the grid
        CustomerDataGrid.DataSource = _
            myDataSet.Tables("Customers").DefaultView
    End Sub 'New
Posted
Updated 20-Jul-11 2:08am
v2

Write another query by separating with ;
Dim commandString As String = _
        "Select CompanyName, ContactName, ContactTitle, " & _
        "Phone, Fax from Customers; " & _
        " Select * from tablename"

Try to use Stored Procedure[^] always.
Check this link for more info.

http://www.sql-server-performance.com/2003/stored-procedures-basics/[^]
 
Share this answer
 
v2
Comments
sijimann 20-Jul-11 8:31am    
Thanx a lot how do I get to fill the dataset do I fill like this

myDataAdapter.Fill(myDataSet, "Customers"&"Other TableName")
Toniyo Jackson 20-Jul-11 8:36am    
Just use myDataAdapter.Fill(myDataSet)
sijimann 20-Jul-11 8:49am    
Thanx a lot you are a star
Toniyo Jackson 20-Jul-11 8:52am    
You are Welcome :)
[no name] 20-Jul-11 11:55am    
Excellent.+5.
Just because you're coding it in VB doesn't mean you're free from having to be familiar with SQL. Afterall, your command string is SQL. Regardless of whether or not you're writing a stored proc, you still have to know how to write your query. I personally think it's easier to use SQLServer Manager Express to write a query because you can test it without having to continually stop to edit code and compile your app.

In the end, I suspect you want to perform multiple queries and have the returned tables put into your dataset. I found this with a simple google search for "c# multiple tables in dataset":

Multiple Tables in Dataset[^]
 
Share this answer
 
v3
Comments
[no name] 20-Jul-11 11:54am    
Excellent +5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900