Microsoft
Software
Hardware
Network
Question : SQLDataAdapter fill multiple tables in DataSource using one stored procedure
Hello experts,
I am fairly new to VB.NET and I am faced with the following problem:
I am trying to populate two tables in a dataset using a stored procedure. The tables are unrelated and the stored procedure has two separate select statements. When executing the stored procedure in SQL Server Management studio I can see two separate tables.
The dataset as defined in the VB.NET .xsd file has two table definitions.
My issue is that only the first table gets populated. How can I use the same SqlDataAdapter.
Here is how the FillDataSet subroutine looks like
Protected Sub FillDataset(ByVal commandText As String, ByVal dataSet As DataSet, ByVal tableNames As String())
try
Dim sqlCommand As sqlCommand = New sqlCommand(commandText, _conn)
sqlCommand.CommandType = CommandType.StoredProcedur
e
_da = New SqlDataAdapter(sqlCommand)
'If I just call only the first table is filled.
_da.Fill(dataSet, tableNames(0)
'If I just pass the dataSet
_da.MissingSchemaAction = MissingSchemaAction.AddWit
hKey
_da.Fill(dataSet)
'I also tried to loop through the tables
for iTableCount = 0 to tableNames.Length - 1
_da.Fill(dataSet.Tables(iT
ableCount)
.DataSet, tableNames(iTableCount))
Next
' I also tried adding tableMappings but still not success.
I try to determine if both tables were filled the following way:
ds.Table1.Rows.Count > 0
ds.Table2.Rows.Count = 0 ' Meaning that the table is empty.
Answer : SQLDataAdapter fill multiple tables in DataSource using one stored procedure
Do you have two selects in your stored proc?
Also you need to add table mappings...
and Datarelations if any...
Check out :
http://support.microsoft.c
om/kb/3227
93
http://www.eggheadcafe.com
/conversat
ion.aspx?
m
essageid=3
2696857&th
readid=326
96845
Random Solutions
When exporting Access 2003 report to Excel 2003, I get a message "File Error, Some number formats may have been lost." and my Date field is corrupted to a seemingly random number.
Get username and role c#.net
Windows 2000 theme
Create batch .bat file that does not wait for an application
Expanding Fields in MS Access Report
How to target search core results to an audience
ADMT 3.0 example include file
Exchange Tabs missing in ADUC and Windows 7/ESM7
Query Field With Date/Time
Populate a combo box based on selection from previous combo box