Fill method for Dataset

Discussion in 'ASP .Net' started by Marc Llenas, Feb 20, 2006.

  1. Marc Llenas

    Marc Llenas Guest

    Hello all,

    I'm new to ASP.NET and I have a question regarding the fill method of a
    dataset.

    Here is my code

    1 Dim objConn As OleDbConnection
    2 Dim objAdapt As OleDbDataAdapter
    3 Dim strConn As String
    4 Dim strSQL As String
    5 Dim objDataSet As New DataSet
    6
    7 'Build the connection string
    8 strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    Server.MapPath("App_data\backend.mdb") & ";Persist Security Info=False"
    9
    10 'Build the SQL string
    11 strSQL = "SELECT TblProperty.ProID, TblProperty.ProName,
    [TblCategory]![CatNumber] & ' Estrellas (' & [TblCategory]![CatStars] & ')'
    AS FullCat, [TblProperty]![ProCity] & ' (' & [TblProperty]![ProProvince] &
    ')' AS FullLocation, TblProperty.ProDescription, TblProperty.ProImagePath,
    TblProperty.ProLogo1Path, TblProperty.ProLogo2Path,
    TblProperty.ProLogo3Path, TblProperty.ProLogo4Path FROM TblCategory INNER
    JOIN TblProperty ON TblCategory.CatID = TblProperty.ProCatID;"
    12
    13 'Create the connection and command objects
    14 objConn = New OleDbConnection(strConn)
    15 objAdapt = New OleDbDataAdapter(strSQL, objConn)
    16
    17 'Fill the dataset with the results of the query
    18 objAdapt.Fill(objDataSet, "TblProperty")
    19
    20 'Set the repeater's source to the dataset and bind the data
    21 objRepeater.DataSource = objDataSet.Tables("TblProperty").DefaultView
    22 objRepeater.DataBind()

    My question is related to line's 18 and 21. In all examples I have reviewed
    the SQL string relates to a single table and the name of that table is
    refered in those lines.

    In my case my SQL sentence has a join so I'm not sure how to go about it.

    Any suggestions?

    Thanks,

    Marc
    Marc Llenas, Feb 20, 2006
    #1
    1. Advertising

  2. Hi
    You can use DataTable's TableName property :

    objAdapt.Fill(objDataSet, objDataSet.Tables[0].TablenName)

    Best Regards,
    A.Hadi
    Aboulfazl Hadi, Feb 20, 2006
    #2
    1. Advertising

  3. Marc Llenas

    vinu Guest

    Hello Mark,

    There is nothing wrong with you code. I thing you are getting confused. The
    simplest way to understand this is..
    When you execute the sql statement you get the resultset which satisfies the
    all your join condition, that resultset then get loaded in to dataset.
    Think like dataset as basket, where you can store lot of item. The table
    name you give in the Fill statement has nothing to do with actual table, you
    can specify any name.

    Hope its clear now....

    vinu





    "Marc Llenas" <> wrote in message
    news:%...
    > Hello all,
    >
    > I'm new to ASP.NET and I have a question regarding the fill method of a
    > dataset.
    >
    > Here is my code
    >
    > 1 Dim objConn As OleDbConnection
    > 2 Dim objAdapt As OleDbDataAdapter
    > 3 Dim strConn As String
    > 4 Dim strSQL As String
    > 5 Dim objDataSet As New DataSet
    > 6
    > 7 'Build the connection string
    > 8 strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > Server.MapPath("App_data\backend.mdb") & ";Persist Security Info=False"
    > 9
    > 10 'Build the SQL string
    > 11 strSQL = "SELECT TblProperty.ProID, TblProperty.ProName,
    > [TblCategory]![CatNumber] & ' Estrellas (' & [TblCategory]![CatStars] &
    > ')' AS FullCat, [TblProperty]![ProCity] & ' (' &
    > [TblProperty]![ProProvince] & ')' AS FullLocation,
    > TblProperty.ProDescription, TblProperty.ProImagePath,
    > TblProperty.ProLogo1Path, TblProperty.ProLogo2Path,
    > TblProperty.ProLogo3Path, TblProperty.ProLogo4Path FROM TblCategory INNER
    > JOIN TblProperty ON TblCategory.CatID = TblProperty.ProCatID;"
    > 12
    > 13 'Create the connection and command objects
    > 14 objConn = New OleDbConnection(strConn)
    > 15 objAdapt = New OleDbDataAdapter(strSQL, objConn)
    > 16
    > 17 'Fill the dataset with the results of the query
    > 18 objAdapt.Fill(objDataSet, "TblProperty")
    > 19
    > 20 'Set the repeater's source to the dataset and bind the data
    > 21 objRepeater.DataSource = objDataSet.Tables("TblProperty").DefaultView
    > 22 objRepeater.DataBind()
    >
    > My question is related to line's 18 and 21. In all examples I have
    > reviewed the SQL string relates to a single table and the name of that
    > table is refered in those lines.
    >
    > In my case my SQL sentence has a join so I'm not sure how to go about it.
    >
    > Any suggestions?
    >
    > Thanks,
    >
    > Marc
    >
    >
    >
    vinu, Feb 20, 2006
    #3
  4. Marc Llenas

    Marc Llenas Guest

    Gotcha, so the name I give in the Fill statement is like an "alias" to
    reference it later on the repeater's DataSource.

    Thanks a lot Vinu, I think it's clear now.

    Cheers,

    Marc


    "vinu" <> escribió en el mensaje
    news:...
    > Hello Mark,
    >
    > There is nothing wrong with you code. I thing you are getting confused.
    > The simplest way to understand this is..
    > When you execute the sql statement you get the resultset which satisfies
    > the all your join condition, that resultset then get loaded in to dataset.
    > Think like dataset as basket, where you can store lot of item. The table
    > name you give in the Fill statement has nothing to do with actual table,
    > you can specify any name.
    >
    > Hope its clear now....
    >
    > vinu
    >
    >
    >
    >
    >
    > "Marc Llenas" <> wrote in message
    > news:%...
    >> Hello all,
    >>
    >> I'm new to ASP.NET and I have a question regarding the fill method of a
    >> dataset.
    >>
    >> Here is my code
    >>
    >> 1 Dim objConn As OleDbConnection
    >> 2 Dim objAdapt As OleDbDataAdapter
    >> 3 Dim strConn As String
    >> 4 Dim strSQL As String
    >> 5 Dim objDataSet As New DataSet
    >> 6
    >> 7 'Build the connection string
    >> 8 strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    >> Server.MapPath("App_data\backend.mdb") & ";Persist Security Info=False"
    >> 9
    >> 10 'Build the SQL string
    >> 11 strSQL = "SELECT TblProperty.ProID, TblProperty.ProName,
    >> [TblCategory]![CatNumber] & ' Estrellas (' & [TblCategory]![CatStars] &
    >> ')' AS FullCat, [TblProperty]![ProCity] & ' (' &
    >> [TblProperty]![ProProvince] & ')' AS FullLocation,
    >> TblProperty.ProDescription, TblProperty.ProImagePath,
    >> TblProperty.ProLogo1Path, TblProperty.ProLogo2Path,
    >> TblProperty.ProLogo3Path, TblProperty.ProLogo4Path FROM TblCategory INNER
    >> JOIN TblProperty ON TblCategory.CatID = TblProperty.ProCatID;"
    >> 12
    >> 13 'Create the connection and command objects
    >> 14 objConn = New OleDbConnection(strConn)
    >> 15 objAdapt = New OleDbDataAdapter(strSQL, objConn)
    >> 16
    >> 17 'Fill the dataset with the results of the query
    >> 18 objAdapt.Fill(objDataSet, "TblProperty")
    >> 19
    >> 20 'Set the repeater's source to the dataset and bind the data
    >> 21 objRepeater.DataSource = objDataSet.Tables("TblProperty").DefaultView
    >> 22 objRepeater.DataBind()
    >>
    >> My question is related to line's 18 and 21. In all examples I have
    >> reviewed the SQL string relates to a single table and the name of that
    >> table is refered in those lines.
    >>
    >> In my case my SQL sentence has a join so I'm not sure how to go about it.
    >>
    >> Any suggestions?
    >>
    >> Thanks,
    >>
    >> Marc
    >>
    >>
    >>

    >
    >
    Marc Llenas, Feb 20, 2006
    #4
    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. Mark Kamoski
    Replies:
    0
    Views:
    2,876
    Mark Kamoski
    Sep 17, 2003
  2. Alex Papadimoulis

    Re: how-to fill a DataSet from an OleDbDataReader

    Alex Papadimoulis, Sep 17, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    888
    Alex Papadimoulis
    Sep 18, 2003
  3. Jay Balapa
    Replies:
    0
    Views:
    452
    Jay Balapa
    Sep 17, 2003
  4. Christian Pické

    Re: how-to fill a DataSet from an OleDbDataReader

    Christian Pické, Sep 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,373
    Christian Pické
    Sep 17, 2003
  5. William Ryan
    Replies:
    0
    Views:
    509
    William Ryan
    Sep 17, 2003
Loading...

Share This Page