Results 1 to 6 of 6

Thread: [2005] Fill a dataset with 2 unrelated Tables.

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2005] Fill a dataset with 2 unrelated Tables.

    Hello,

    Just looking at your code, but could you not use just 1 adatper

    i.e.
    vb Code:
    1. Dim da As New System.Data.SqlClient.SqlDataAdapter()
    2.             Dim cmd As New System.Data.SqlClient.SqlCommand()
    3.             Dim ds As DataSet
    4.  
    5.             cmd.CommandText = "Select * From Table1"
    6.             cmd.CommandType = CommandType.Text
    7.             da.SelectCommand = cmd
    8.             da.Fill(ds, "Table1")
    9.  
    10.             cmd.CommandText = "Select * From Table2"
    11.             cmd.CommandType = CommandType.Text
    12.             da.SelectCommand = cmd
    13.             da.Fill(ds, "Table2")
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Fill a dataset with 2 unrelated Tables.

    Quote Originally Posted by steve_rm
    Hello,

    Just looking at your code, but could you not use just 1 adatper

    i.e.
    vb Code:
    1. Dim da As New System.Data.SqlClient.SqlDataAdapter()
    2.             Dim cmd As New System.Data.SqlClient.SqlCommand()
    3.             Dim ds As DataSet
    4.  
    5.             cmd.CommandText = "Select * From Table1"
    6.             cmd.CommandType = CommandType.Text
    7.             da.SelectCommand = cmd
    8.             da.Fill(ds, "Table1")
    9.  
    10.             cmd.CommandText = "Select * From Table2"
    11.             cmd.CommandType = CommandType.Text
    12.             da.SelectCommand = cmd
    13.             da.Fill(ds, "Table2")
    You could but you wouldn't. If you are using DataAdapters then that would imply that you would need to Update the data too. If you didn't need to update the data then you should use a DataReader to load the data, in which case you could use the same Command with different CommandText each time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    42

    Resolved Re: [2005] Fill a dataset with 2 unrelated Tables.

    Didnt figure that. I am going to need to update both tables.
    Tx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width