Results 1 to 4 of 4

Thread: Use multiple datareader

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    1

    Question Use multiple datareader

    Hi all!!!!!

    In VB6.0 we use to write a code like this...........

    //////////////////////////////////////////////////////////////////////////

    Dim con as adodb.connection
    Dim rs as adodb.recordset
    Dim rs1 as adodb.recordset

    set con=new adodb.connection

    with con
    .provider="SQLOLEDB"
    .connectionstring="xyz"
    .open
    end with

    set rs=new adodb.recordset
    set rs1=new adodb.recordset

    st="select sch_code from sch_master order by 1"
    rs.open st,con

    if not rs.eof then
    while not rs.eof
    st="select f_val from f_value where sch_code='"& rs("sch_code") &"'"
    rs1.open st,con
    if not rs1.eof then

    ''/////////code to display data in grid///////////////
    end if
    rs1.close
    rs.movenext
    wend
    end if


    ///////////////////////////////////////////////////////////////////////////////

    How can I perform the same operation as stated above using ADO.NET(Dataset/DataReader) and the program should must have only one connection.


    Please Reply Me

    Manish Raj


  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Forget about old ADO and go with ADO.NET , here's an example shows you how to connectio DataGrid to Dataset :

    VB Code:
    1. 'Establish a connection to the data source.
    2.         Dim sConnectionString As String
    3.  
    4.         sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.             "Data Source=d:\My Documents\db1.mdb"
    6.         Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
    7.         objConn.Open()
    8.  
    9.         Dim da As New System.Data.OleDb.OleDbDataAdapter("Table1", objConn)
    10.  
    11.         Dim ds As New DataSet("AccessDS")
    12.  
    13.         da.Fill(ds, "AccessTable")
    14.  
    15.         DataGrid1.SetDataBinding(ds, "AccessTable")
    16.      
    17.        objConn.Close()

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    That is what he was asking about. You can only have 1 DataReader per connection. Of course if you are using a Dataset, you dont need a DataReader, and hould just use the DataAdapter to fill the Dataset and use the Data in that.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Junior Member
    Join Date
    Apr 2003
    Posts
    18
    manishraj,

    you will need to add then remove a datatable for each loop through the main recordset. Use a GUID or Key for the table name, as the old data may not be destroyed on remove of the table form the dataset. you are only allowed one dataadapter open per connection. keep in mind the connection pooling is enabled with VB.NET, so if you create a new connection with the same connection string, you are actully only getting a pointer to the connection pool.
    www.WinMgmt.com
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width