SqlDataAdapter

Discussion in 'ASP .Net Web Controls' started by susie, Oct 24, 2003.

  1. susie

    susie Guest

    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.
     
    susie, Oct 24, 2003
    #1
    1. Advertising

  2. 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.


    --------------------
    > Content-Class: urn:content-classes:message
    > From: "susie" <>
    > Sender: "susie" <>
    > Subject: SqlDataAdapter
    > Date: Fri, 24 Oct 2003 06:37:38 -0700
    > Lines: 12
    > Message-ID: <0b1101c39a33$fd737e00$>
    > MIME-Version: 1.0
    > Content-Type: text/plain;
    > charset="iso-8859-1"
    > Content-Transfer-Encoding: 7bit
    > X-Newsreader: Microsoft CDO for Windows 2000
    > X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > Thread-Index: AcOaM/1zYDh4cDm8RJy5ugDfb2fmgg==
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > Path: cpmsftngxa06.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:15603
    > NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > 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.
    >
     
    Mike Moore [MSFT], Oct 24, 2003
    #2
    1. Advertising

  3. susie

    James Curran Guest

    susie wrote:
    > 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.

    --
    Truth,
    James Curran [MVP]
    www.NJTheater.com (Professional)
    www.NovelTheory.com (Personal)
     
    James Curran, Oct 26, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zhaoJian
    Replies:
    0
    Views:
    1,052
    zhaoJian
    Nov 6, 2003
  2. Dan

    TimeOut on SqlDataAdapter.Fill

    Dan, Apr 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    7,967
  3. Jerry Higgins
    Replies:
    6
    Views:
    637
    Jerry Higgins
    Apr 21, 2004
  4. Jerry Higgins
    Replies:
    1
    Views:
    833
    Curt_C [MVP]
    Apr 21, 2004
  5. Bob of the West
    Replies:
    1
    Views:
    2,959
    William F. Robertson, Jr.
    May 17, 2004
Loading...

Share This Page