Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simple Dataset question
Message
 
À
02/08/2002 12:06:57
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00685449
Message ID:
00685522
Vues:
32
Actually, Bonnie Berent cleared this one up for me. The Dataadapter is useful for filling datasets. You don't need to create the elaborate set of table mappings that are required for updates.

You can create your dataset and assocated tables and use data readers to fill the data sets manually. This is the focal point of my next Code Magazine article. Here is some VB code that fills a dataset w/o a data adapter:

I use the data reader info to populate the column defintions first and then I insert the data into the table. You would need to scale this code to handle multiple tables, but that should be a snap.

In retrospect, I guess it would be more efficient to use the data adapter to simply fill the dataset. But, it is nice to see that you can handle this stuff yourself!!

Good luck!
        Dim authorreader As SqlDataReader
        Dim item As Int16
        Dim newrow As DataRow

        SelectCommand.Parameters("@" + KeyField).Value = id

        GetData = New DataSet()
        GetData.Tables.Add(TableName)

        authorreader = SelectCommand.ExecuteReader
        For item = 0 To authorreader.FieldCount - 1
            GetData.Tables(0).Columns.Add(authorreader.GetName(item), authorreader.GetFieldType(item))
        Next

        While authorreader.Read
            newrow = GetData.Tables(0).NewRow
            For item = 0 To authorreader.FieldCount - 1
                newrow(item) = authorreader.Item(item)
            Next
            GetData.Tables(0).Rows.Add(newrow)
        End While
        authorreader.Close()
>I'm glad you thought that was a good question, because (now) I have a really stupid question.
>
>If I want to do an SQL query and bring back the results in a dataset, do I *have* to use the data adapter?
>
>I have a form where I need to bring back 3 data tables...so I do a
>
>MyAdapter = new SqlDataAdapter("SELECT * FROM TABLE1; SELECT * FROM TABLE2; SELECT * FROM TABLE3,MyConnection)
>
>DsReturn = new DataSet();
>MyAdapter.Fill(DsReturn,"whatever");
>
>Is there a 'simpler' way to do this? About the only requirement is that it has to be a dataset, it can't be a data reader.
>
>Thanks,
>Kevin
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform