Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

ok, let's say i have a typed DataSet with multiple tables and i want to populate it from a database. I know i have to populate the tables with parent fields first, for example let' say i have three tables Customer, Order, CustOrder. Customer and Order are parents and CustOrder is a child table. So what i have to do it something like this:

 

Public Function FillDataTable(ByVal argsTableName As String, ByRef argsDataSet As DataSet)

'Variables declaration and initialization.

Dim localConn As OracleConnection 'the Oracle connection variable

Dim localOracleCommand As OracleCommand 'the Oracle Command variable

Dim locAdapter As New OracleDataAdapter

 

'Variables initialization.

localConn = New OracleConnection

localConn.ConnectionString = OracleConnectionString

 

'Open connection to an instance of the Oracle database.

Try

localConn.Open()

 

'Initialize Oracle command and set necessary parameters.

localOracleCommand = New OracleCommand

localOracleCommand.Connection = localConn

localOracleCommand.CommandText = "SELECT * FROM " & argsTableName

 

'Set "SelectCommand" parameter of OracleAdapter instance.

locAdapter.SelectCommand = localOracleCommand

 

locAdapter.Fill(argsDataSet, argsTableName)

 

Catch Ex As Exception

Throw Ex

Finally

'Close datebase connection.

localConn.Close()

End Try 'End Try

End Function

 

So i call this function for each table in order of parent to child, i.e. for the above tables:

 

FillDataTable(ds.CUSTOMER.TableName, ds)

FillDataTable(ds.ORDER.TableName, ds)

FillDataTable(ds.CUSTORDER.TableName, ds)

 

So for three tables that's ok, but what if i had 20 or 30 or 50 tables in my typed dataset? I can't use the above method in that case, i have to find something more elegant. Any ideas?

The only thing i can think of right now is to disable the constraints before filling the data set, then fill it, and then turn the constraints on again.

 

Thanks all.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...