SqlDataAdapter

S

susie

How to specify table names in SqlDataAdapter fill
parameter if I have more than one tables in my select
statement

sqlStatement="select i.*, p.Prod# from pInv i, pPrice p " _
& "where i.DBF=p.DBF " _
& "Order By " & SortExpression & " " & SortOrder

DS = new DataSet()
MyCommand.Fill(DS, "?")

Thank you.
 
M

Mike Moore [MSFT]

Hi Susie,

Below is a sample which shows selection from multiple tables as you
requested. For more information, please see this article.
301216 HOW TO: Populate a DataSet Object from a Database by Using Visual
Basic
http://kb/article.asp?id=Q301216

I placed a datagrid on a page and left it with autogenerate columns. Then I
added the following to the code-behind.

If Not IsPostBack Then
Bind()
End If
End Sub

Private Sub Bind()
Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT a.au_fname, a.au_lname, t.title
FROM titles t inner join titleauthor ta on t.title_id = ta.title_id inner
join authors a on ta.au_id = a.au_id"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
Dim sqlAdapter As New SqlClient.SqlDataAdapter(sqlCommand)
Dim ds As New Data.DataSet
sqlAdapter.Fill(ds, "data")
DataGrid1.DataSource = ds.Tables("data")
DataGrid1.DataBind()
sqlAdapter.Dispose()
sqlCommand.Dispose()
sqlConnection.Close()
sqlConnection.Dispose()
End Sub


Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
J

James Curran

susie said:
How to specify table names in SqlDataAdapter fill
parameter if I have more than one tables in my select
statement

The result set from the SELECT forms a new "table" (which only exists
inside the DataSet). The name of this new table does not have to be (and
probably should not be) the same as a table in your database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top