|
-
Jul 16th, 2007, 07:29 PM
#1
Thread Starter
Member
[2005] Fill a dataset with 2 unrelated Tables.
I guess This is a two part Question: first part being How to load 2 tables from the same database where both tables can not be joined by a Common field?
Would I have to Do 2 Different select Commands ? as in the below example.
My second part. Im not sure how to syntax the Dataset to store the second table with fill. Here is the code I am trying to use:
Code:
Private Sub ManagersForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Db As String
Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & "\EmployeeVzwSlots.mdb"
Con.ConnectionString = Db
OleDbmcmnds(0) = New OleDbCommand("SELECT AwardSubject, SubjectSpinsAwarded FROM AwardedSubjects")
OleDbmcmnds(1) = New OleDbCommand("SELECT Id, FirstName, LastName, SpinsAwarded, SpinsUsed, MoneyWon FROM EmployeeInfo")
For index As Int16 = 0 To 1
DA.SelectCommand = OleDbmcmnds(index)
DA.SelectCommand.Connection = Con
DA.Fill(DS.Tables(index))
Next index
-
Jul 16th, 2007, 07:33 PM
#2
Thread Starter
Member
Re: [2005] Fill a dataset with 2 unrelated Tables.
Sorry, Just noticed I posted in the wrong section of Forum.
-
Jul 17th, 2007, 02:06 AM
#3
Re: [2005] Fill a dataset with 2 unrelated Tables.
vb.net Code:
Dim adp1 As New OleDbCommand("SELECT * FROM Table1", con)
Dim adp2 As New OleDbCommand("SELECT * FROM Table2", con)
adp1.Fill(myDataSet, "Table1")
adp2.Fill(myDataSet, "Table2")
-
Jul 17th, 2007, 02:22 AM
#4
Frenzied Member
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:
Dim da As New System.Data.SqlClient.SqlDataAdapter()
Dim cmd As New System.Data.SqlClient.SqlCommand()
Dim ds As DataSet
cmd.CommandText = "Select * From Table1"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "Table1")
cmd.CommandText = "Select * From Table2"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "Table2")
-
Jul 17th, 2007, 02:24 AM
#5
Re: [2005] Fill a dataset with 2 unrelated Tables.
 Originally Posted by steve_rm
Hello,
Just looking at your code, but could you not use just 1 adatper
i.e.
vb Code:
Dim da As New System.Data.SqlClient.SqlDataAdapter()
Dim cmd As New System.Data.SqlClient.SqlCommand()
Dim ds As DataSet
cmd.CommandText = "Select * From Table1"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "Table1")
cmd.CommandText = "Select * From Table2"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
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.
-
Jul 17th, 2007, 10:43 AM
#6
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|