Recordsets in .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CR

    Recordsets in .NET

    I am making the switch to .NET from VB6. In VB6 you could access data
    by using the Data Environment and Data Control. I found both to be
    totally useless. I can just as easily accomplish the same task with
    code. For example if I wanted to populate a textbox I would do
    something like this:

    Dim rst As New Recordset
    Dim cnn as New Connection

    cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data
    Source=c:\test\ test.mdb;"
    rst.Open "Select * From Table1", cnn
    Text1.Text = rst!Field1

    Using code, in my opinion, is much easier and more flexible than using
    the Data Environment Wizard and the data control. Plus you can use in
    in your VBA macros.

    I have a tutorial on .NET but it seems to only cover .NET's version of
    the Data Environment and Data control. I think they call it the Server
    Explorer and Data Adapter.

    Is there a way to access data using straight VB code like I did in
    VB6?

    Thanks!

    Chuck.
  • Bin Song

    #2
    Recordsets in .NET

    You can do the same in .NET (which I prefer over those
    drag and drop wizards):

    Dim cnn As OleDbConnection = New OleDbConnection
    ("Provider=Micr osoft.Jet.OLEDB .4.0; Data
    Source=c:\test\ test.mdb;")
    cnn.Open()
    Dim cmd As OleDbCommand = New OleDbCommand("S elect * From
    Table1", cnn)
    Dim rdr As OleDbDataReader = cmd.ExecuteRead er()
    If rdr.Read() Then
    Text1.Text = rdr(0)
    End If

    Bin Song, MCP
    [color=blue]
    >-----Original Message-----
    >I am making the switch to .NET from VB6. In VB6 you could[/color]
    access data[color=blue]
    >by using the Data Environment and Data Control. I found[/color]
    both to be[color=blue]
    >totally useless. I can just as easily accomplish the same[/color]
    task with[color=blue]
    >code. For example if I wanted to populate a textbox I[/color]
    would do[color=blue]
    >something like this:
    >
    >Dim rst As New Recordset
    >Dim cnn as New Connection
    >
    >cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data
    >Source=c:\test \test.mdb;"
    >rst.Open "Select * From Table1", cnn
    >Text1.Text = rst!Field1
    >
    >Using code, in my opinion, is much easier and more[/color]
    flexible than using[color=blue]
    >the Data Environment Wizard and the data control. Plus[/color]
    you can use in[color=blue]
    >in your VBA macros.
    >
    >I have a tutorial on .NET but it seems to only[/color]
    cover .NET's version of[color=blue]
    >the Data Environment and Data control. I think they call[/color]
    it the Server[color=blue]
    >Explorer and Data Adapter.
    >
    >Is there a way to access data using straight VB code like[/color]
    I did in[color=blue]
    >VB6?
    >
    >Thanks!
    >
    >Chuck.
    >.
    >[/color]

    Comment

    • Cor

      #3
      Re: Recordsets in .NET

      Hi CR,

      In addition to Bing Song a little sample, how to use it with a dataset
      Just typed from your example, so watch typos.

      \\\\[color=blue]
      > dim connString as string = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
      > Source=c:\test\ test.mdb;"[/color]
      dim SqlString as string = "Select * From Table1"
      Dim conn As New OledbConnection (connString)
      Dim cmd As New OleDbCommand(sq lStr, Conn)
      Dim ds As New DataSet
      Dim da As New OleDbDataAdapte r(cmd)
      da.Fill(ds, "Table1")
      conn.close
      ///

      I hope this helps a little bit.

      Cor


      Comment

      • CR

        #4
        Re: Recordsets in .NET

        "Bin Song" <anonymous@disc ussions.microso ft.com> wrote in message news:<027401c3b b75$f2da5af0$a4 01280a@phx.gbl> ...


        Thanks! That saves me a lot of trouble.

        [color=blue]
        > You can do the same in .NET (which I prefer over those
        > drag and drop wizards):
        >
        > Dim cnn As OleDbConnection = New OleDbConnection
        > ("Provider=Micr osoft.Jet.OLEDB .4.0; Data
        > Source=c:\test\ test.mdb;")
        > cnn.Open()
        > Dim cmd As OleDbCommand = New OleDbCommand("S elect * From
        > Table1", cnn)
        > Dim rdr As OleDbDataReader = cmd.ExecuteRead er()
        > If rdr.Read() Then
        > Text1.Text = rdr(0)
        > End If
        >
        > Bin Song, MCP
        >[color=green]
        > >-----Original Message-----
        > >I am making the switch to .NET from VB6. In VB6 you could[/color]
        > access data[color=green]
        > >by using the Data Environment and Data Control. I found[/color]
        > both to be[color=green]
        > >totally useless. I can just as easily accomplish the same[/color]
        > task with[color=green]
        > >code. For example if I wanted to populate a textbox I[/color]
        > would do[color=green]
        > >something like this:
        > >
        > >Dim rst As New Recordset
        > >Dim cnn as New Connection
        > >
        > >cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data
        > >Source=c:\test \test.mdb;"
        > >rst.Open "Select * From Table1", cnn
        > >Text1.Text = rst!Field1
        > >
        > >Using code, in my opinion, is much easier and more[/color]
        > flexible than using[color=green]
        > >the Data Environment Wizard and the data control. Plus[/color]
        > you can use in[color=green]
        > >in your VBA macros.
        > >
        > >I have a tutorial on .NET but it seems to only[/color]
        > cover .NET's version of[color=green]
        > >the Data Environment and Data control. I think they call[/color]
        > it the Server[color=green]
        > >Explorer and Data Adapter.
        > >
        > >Is there a way to access data using straight VB code like[/color]
        > I did in[color=green]
        > >VB6?
        > >
        > >Thanks!
        > >
        > >Chuck.
        > >.
        > >[/color][/color]

        Comment

        • CR

          #5
          Re: Recordsets in .NET

          "Cor" <non@non.com> wrote in message news:<#9F3HL#uD HA.2220@TK2MSFT NGP09.phx.gbl>. ..

          I appreciate the help!

          Chuck.

          [color=blue]
          > Hi CR,
          >
          > In addition to Bing Song a little sample, how to use it with a dataset
          > Just typed from your example, so watch typos.
          >
          > \\\\[color=green]
          > > dim connString as string = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
          > > Source=c:\test\ test.mdb;"[/color]
          > dim SqlString as string = "Select * From Table1"
          > Dim conn As New OledbConnection (connString)
          > Dim cmd As New OleDbCommand(sq lStr, Conn)
          > Dim ds As New DataSet
          > Dim da As New OleDbDataAdapte r(cmd)
          > da.Fill(ds, "Table1")
          > conn.close
          > ///
          >
          > I hope this helps a little bit.
          >
          > Cor[/color]

          Comment

          • CR

            #6
            Re: Recordsets in .NET

            "Cor" <non@non.com> wrote in message news:<#9F3HL#uD HA.2220@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
            > Hi CR,
            >
            > In addition to Bing Song a little sample, how to use it with a dataset
            > Just typed from your example, so watch typos.
            >
            > \\\\[color=green]
            > > dim connString as string = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
            > > Source=c:\test\ test.mdb;"[/color]
            > dim SqlString as string = "Select * From Table1"
            > Dim conn As New OledbConnection (connString)
            > Dim cmd As New OleDbCommand(sq lStr, Conn)
            > Dim ds As New DataSet
            > Dim da As New OleDbDataAdapte r(cmd)
            > da.Fill(ds, "Table1")
            > conn.close[/color]

            I figured out how to access data in the DataReader but I can't figure
            out how to access the data in the DataSet. In this example if I had a
            field in Table1 called Field1, how would I get to the value in Field1?

            Comment

            • Armin Zingler

              #7
              Re: Recordsets in .NET

              "CR" <cr113@hotmail. com> schrieb[color=blue]
              > I figured out how to access data in the DataReader but I can't
              > figure out how to access the data in the DataSet. In this example if
              > I had a field in Table1 called Field1, how would I get to the value
              > in Field1?[/color]

              Only a question: Have you already read the documentation of the DataSet (and
              other ADO.NET related topics)?


              --
              Armin




              Comment

              • Cor

                #8
                Re: Recordsets in .NET

                [color=blue]
                > I figured out how to access data in the DataReader but I can't figure
                > out how to access the data in the DataSet. In this example if I had a
                > field in Table1 called Field1, how would I get to the value in Field1?[/color]

                For the first record(row)

                ds.tables(0).ro ws(0).item("Fie ld1")

                "> > \\\\[color=blue][color=green][color=darkred]
                > > > dim connString as string = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
                > > > Source=c:\test\ test.mdb;"[/color]
                > > dim SqlString as string = "Select * From Table1"
                > > Dim conn As New OledbConnection (connString)
                > > Dim cmd As New OleDbCommand(sq lStr, Conn)
                > > Dim ds As New DataSet
                > > Dim da As New OleDbDataAdapte r(cmd)
                > > da.Fill(ds, "Table1")
                > > conn.close[/color]
                >[/color]


                Comment

                • CR

                  #9
                  Re: Recordsets in .NET

                  "Armin Zingler" <az.nospam@free net.de> wrote in message news:<e2uVj4BwD HA.684@TK2MSFTN GP09.phx.gbl>.. .[color=blue]
                  > "CR" <cr113@hotmail. com> schrieb[color=green]
                  > > I figured out how to access data in the DataReader but I can't
                  > > figure out how to access the data in the DataSet. In this example if
                  > > I had a field in Table1 called Field1, how would I get to the value
                  > > in Field1?[/color]
                  >
                  > Only a question: Have you already read the documentation of the DataSet (and
                  > other ADO.NET related topics)?[/color]

                  Some of the online help, but it's a little overwhelming. For example
                  I'm not sure if I should even be using the DataSet object, maybe I
                  only need the DataReader. What documentation would you recommend I
                  read to get a good overview of this topic?

                  Comment

                  • CR

                    #10
                    Re: Recordsets in .NET

                    "Cor" <non@non.com> wrote in message news:<e0DK#AIwD HA.2352@TK2MSFT NGP09.phx.gbl>. ..[color=blue][color=green]
                    > > I figured out how to access data in the DataReader but I can't figure
                    > > out how to access the data in the DataSet. In this example if I had a
                    > > field in Table1 called Field1, how would I get to the value in Field1?[/color]
                    >
                    > For the first record(row)
                    >
                    > ds.tables(0).ro ws(0).item("Fie ld1")[/color]

                    Works! Thanks!

                    Chuck.

                    Comment

                    • Armin Zingler

                      #11
                      Re: Recordsets in .NET

                      "CR" <cr113@hotmail. com> schrieb[color=blue]
                      > "Armin Zingler" <az.nospam@free net.de> wrote in message
                      > news:<e2uVj4BwD HA.684@TK2MSFTN GP09.phx.gbl>.. .[color=green]
                      > > "CR" <cr113@hotmail. com> schrieb[color=darkred]
                      > > > I figured out how to access data in the DataReader but I can't
                      > > > figure out how to access the data in the DataSet. In this example
                      > > > if I had a field in Table1 called Field1, how would I get to the
                      > > > value in Field1?[/color]
                      > >
                      > > Only a question: Have you already read the documentation of the
                      > > DataSet (and other ADO.NET related topics)?[/color]
                      >
                      > Some of the online help, but it's a little overwhelming. For
                      > example I'm not sure if I should even be using the DataSet object,
                      > maybe I only need the DataReader. What documentation would you
                      > recommend I read to get a good overview of this topic?[/color]

                      Concerning the Dataset I recommend
                      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

                      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                      If you only want to process data from the database sequentially, you can use
                      a DataReader. As the name says, it is used to read the data from the
                      databse. A dataset is an object that locally stores the content of the
                      records read, and you'll be able to access the records randomly.


                      --
                      Armin






                      Comment

                      • CR

                        #12
                        Re: Recordsets in .NET

                        "Armin Zingler" <az.nospam@free net.de> wrote in message
                        [color=blue][color=green]
                        > > Some of the online help, but it's a little overwhelming. For
                        > > example I'm not sure if I should even be using the DataSet object,
                        > > maybe I only need the DataReader. What documentation would you
                        > > recommend I read to get a good overview of this topic?[/color]
                        >
                        > Concerning the Dataset I recommend
                        > http://msdn.microsoft.com/library/en...ngdatasets.asp
                        > http://msdn.microsoft.com/library/en...riDatasets.asp
                        >
                        > If you only want to process data from the database sequentially, you can use
                        > a DataReader. As the name says, it is used to read the data from the
                        > databse. A dataset is an object that locally stores the content of the
                        > records read, and you'll be able to access the records randomly.[/color]

                        I just found a good book that also has a nice summary of the dataset
                        object. I hate to ask stupid questions but I'm in that awkward "just
                        starting" phase where you don't even know what questions to ask let
                        alone the answers.

                        Thanks!

                        Chuck.

                        Comment

                        Working...