my_lou Posted May 18, 2004 Posted May 18, 2004 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. Quote
Administrators PlausiblyDamp Posted May 21, 2004 Administrators Posted May 21, 2004 ds.EnforceConstraints = false 'fill dataset here ds.EnforceConstraints = true Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.