Connecting to a DataBase like i did in VB 6

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

    Connecting to a DataBase like i did in VB 6

    Hi all,

    I wrote a cool little database program a while back, in VB6, and im
    intending to rewrite it in .net.

    I am new(ish) to .net, but an old hand at VB5/6.

    In VB i would access the mdb file something like this.

    set db=database
    set db=opendatabase ("mydb.mdb")
    dim rec as recordset
    set rec= db.openrecordse t("select name form names")

    while rec.eof=false
    debug.write(rec !name)
    wend


    How do i do the same in .net, it seems to want me to set up these pages ets,
    but i need to create queries and joins on the fly so data can be accessed as
    the user requests.

    Ive looked in the help, and followed the tutorials, but i cant seem to be
    able to query the db properly, or even connect to it in the way that i want.

    Thanks in advance

    Chris



  • Nick Wilton

    #2
    Re: Connecting to a DataBase like i did in VB 6

    Use the OleDdDataAdapte r, Connection and Command controls in winforms to
    generate the strings that you require for your app. To manipulate these
    strings programmaticall y try using the stringbuilder class.

    "Chris" <xcmharb@lineon e.net> wrote in message
    news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi all,
    >
    > I wrote a cool little database program a while back, in VB6, and im
    > intending to rewrite it in .net.
    >
    > I am new(ish) to .net, but an old hand at VB5/6.
    >
    > In VB i would access the mdb file something like this.
    >
    > set db=database
    > set db=opendatabase ("mydb.mdb")
    > dim rec as recordset
    > set rec= db.openrecordse t("select name form names")
    >
    > while rec.eof=false
    > debug.write(rec !name)
    > wend
    >
    >
    > How do i do the same in .net, it seems to want me to set up these pages[/color]
    ets,[color=blue]
    > but i need to create queries and joins on the fly so data can be accessed[/color]
    as[color=blue]
    > the user requests.
    >
    > Ive looked in the help, and followed the tutorials, but i cant seem to be
    > able to query the db properly, or even connect to it in the way that i[/color]
    want.[color=blue]
    >
    > Thanks in advance
    >
    > Chris
    >
    >
    >[/color]


    Comment

    • Chris

      #3
      Re: Connecting to a DataBase like i did in VB 6

      Can you give a code example that does teh same as my code below please.


      "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
      news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Use the OleDdDataAdapte r, Connection and Command controls in winforms to
      > generate the strings that you require for your app. To manipulate these
      > strings programmaticall y try using the stringbuilder class.
      >
      > "Chris" <xcmharb@lineon e.net> wrote in message
      > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...[color=green]
      > > Hi all,
      > >
      > > I wrote a cool little database program a while back, in VB6, and im
      > > intending to rewrite it in .net.
      > >
      > > I am new(ish) to .net, but an old hand at VB5/6.
      > >
      > > In VB i would access the mdb file something like this.
      > >
      > > set db=database
      > > set db=opendatabase ("mydb.mdb")
      > > dim rec as recordset
      > > set rec= db.openrecordse t("select name form names")
      > >
      > > while rec.eof=false
      > > debug.write(rec !name)[/color][/color]
      rec.movenext[color=blue][color=green]
      > > wend
      > >
      > >
      > > How do i do the same in .net, it seems to want me to set up these pages[/color]
      > ets,[color=green]
      > > but i need to create queries and joins on the fly so data can be[/color][/color]
      accessed[color=blue]
      > as[color=green]
      > > the user requests.
      > >
      > > Ive looked in the help, and followed the tutorials, but i cant seem to[/color][/color]
      be[color=blue][color=green]
      > > able to query the db properly, or even connect to it in the way that i[/color]
      > want.[color=green]
      > >
      > > Thanks in advance
      > >
      > > Chris
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Connecting to a DataBase like i did in VB 6

        Chris,

        Without all error checking.
        \\\
        Dim ds as new dataset
        Dim Conn As New OleDbConnection (Microsoft.Jet. OLEDB.4.0;Data
        Source="C:\mydb .Mdb")
        Dim da As New OleDbDataAdapte r("Select name from names",Conn)
        da.Fill(ds)
        for each dr as datarow in ds.tables(0).ro ws
        console.write(d r("name").ToStr ing)
        next
        ////

        I hope this helps?

        Cor
        [color=blue]
        >
        > I wrote a cool little database program a while back, in VB6, and im
        > intending to rewrite it in .net.
        >
        > I am new(ish) to .net, but an old hand at VB5/6.
        >
        > In VB i would access the mdb file something like this.
        >
        > set db=database
        > set db=opendatabase ("mydb.mdb")
        > dim rec as recordset
        > set rec= db.openrecordse t("select name form names")
        >
        > while rec.eof=false
        > debug.write(rec !name)
        > wend
        >
        >
        > How do i do the same in .net, it seems to want me to set up these pages[/color]
        ets,[color=blue]
        > but i need to create queries and joins on the fly so data can be accessed[/color]
        as[color=blue]
        > the user requests.
        >
        > Ive looked in the help, and followed the tutorials, but i cant seem to be
        > able to query the db properly, or even connect to it in the way that i[/color]
        want.[color=blue]
        >
        > Thanks in advance
        >
        > Chris
        >
        >
        >[/color]


        Comment

        • Nick Wilton

          #5
          Re: Connecting to a DataBase like i did in VB 6

          Something like this:

          Dim mydbConnection As OleDb.OleDbConn ection
          mydbConnection. ConnectionStrin g = "c:\mydb.md b"
          mydbConnection. Open()

          Dim mydbCommand As OleDb.OleDbComm and
          mydbCommand.Con nection = mydbConnection
          mydbCommand.Com mandText = "SELECT * FROM MyTable"

          Dim myreader As oleDB.OleDbData Reader

          myreader = mydbCommand.Exe cuteReader

          You can now inspect the myreader object the same way as you did with your
          recordset.

          "Chris" <xcmharb@lineon e.net> wrote in message
          news:e5K2avXdEH A.2408@tk2msftn gp13.phx.gbl...[color=blue]
          > Can you give a code example that does teh same as my code below please.
          >
          >
          > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
          > news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..[color=green]
          > > Use the OleDdDataAdapte r, Connection and Command controls in winforms[/color][/color]
          to[color=blue][color=green]
          > > generate the strings that you require for your app. To manipulate these
          > > strings programmaticall y try using the stringbuilder class.
          > >
          > > "Chris" <xcmharb@lineon e.net> wrote in message
          > > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...[color=darkred]
          > > > Hi all,
          > > >
          > > > I wrote a cool little database program a while back, in VB6, and im
          > > > intending to rewrite it in .net.
          > > >
          > > > I am new(ish) to .net, but an old hand at VB5/6.
          > > >
          > > > In VB i would access the mdb file something like this.
          > > >
          > > > set db=database
          > > > set db=opendatabase ("mydb.mdb")
          > > > dim rec as recordset
          > > > set rec= db.openrecordse t("select name form names")
          > > >
          > > > while rec.eof=false
          > > > debug.write(rec !name)[/color][/color]
          > rec.movenext[color=green][color=darkred]
          > > > wend
          > > >
          > > >
          > > > How do i do the same in .net, it seems to want me to set up these[/color][/color][/color]
          pages[color=blue][color=green]
          > > ets,[color=darkred]
          > > > but i need to create queries and joins on the fly so data can be[/color][/color]
          > accessed[color=green]
          > > as[color=darkred]
          > > > the user requests.
          > > >
          > > > Ive looked in the help, and followed the tutorials, but i cant seem to[/color][/color]
          > be[color=green][color=darkred]
          > > > able to query the db properly, or even connect to it in the way that i[/color]
          > > want.[color=darkred]
          > > >
          > > > Thanks in advance
          > > >
          > > > Chris
          > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Chris

            #6
            Re: Connecting to a DataBase like i did in VB 6


            Thanks Nick thats great, but how do i get at the data?

            eg.

            debug.writeline (myreader!name)

            just throws an error. AAh i know what i wnnt, but not how to sintax it.

            BTW, all the objects need to be new(ed) on the dims.

            "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
            news:%23Q$CSNYd EHA.1048@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Something like this:
            >
            > Dim mydbConnection As OleDb.OleDbConn ection
            > mydbConnection. ConnectionStrin g = "c:\mydb.md b"
            > mydbConnection. Open()
            >
            > Dim mydbCommand As OleDb.OleDbComm and
            > mydbCommand.Con nection = mydbConnection
            > mydbCommand.Com mandText = "SELECT * FROM MyTable"
            >
            > Dim myreader As oleDB.OleDbData Reader
            >
            > myreader = mydbCommand.Exe cuteReader
            >
            > You can now inspect the myreader object the same way as you did with your
            > recordset.
            >
            > "Chris" <xcmharb@lineon e.net> wrote in message
            > news:e5K2avXdEH A.2408@tk2msftn gp13.phx.gbl...[color=green]
            > > Can you give a code example that does teh same as my code below please.
            > >
            > >
            > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
            > > news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
            > > > Use the OleDdDataAdapte r, Connection and Command controls in winforms[/color][/color]
            > to[color=green][color=darkred]
            > > > generate the strings that you require for your app. To manipulate[/color][/color][/color]
            these[color=blue][color=green][color=darkred]
            > > > strings programmaticall y try using the stringbuilder class.
            > > >
            > > > "Chris" <xcmharb@lineon e.net> wrote in message
            > > > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...
            > > > > Hi all,
            > > > >
            > > > > I wrote a cool little database program a while back, in VB6, and im
            > > > > intending to rewrite it in .net.
            > > > >
            > > > > I am new(ish) to .net, but an old hand at VB5/6.
            > > > >
            > > > > In VB i would access the mdb file something like this.
            > > > >
            > > > > set db=database
            > > > > set db=opendatabase ("mydb.mdb")
            > > > > dim rec as recordset
            > > > > set rec= db.openrecordse t("select name form names")
            > > > >
            > > > > while rec.eof=false
            > > > > debug.write(rec !name)[/color]
            > > rec.movenext[color=darkred]
            > > > > wend
            > > > >
            > > > >
            > > > > How do i do the same in .net, it seems to want me to set up these[/color][/color]
            > pages[color=green][color=darkred]
            > > > ets,
            > > > > but i need to create queries and joins on the fly so data can be[/color]
            > > accessed[color=darkred]
            > > > as
            > > > > the user requests.
            > > > >
            > > > > Ive looked in the help, and followed the tutorials, but i cant seem[/color][/color][/color]
            to[color=blue][color=green]
            > > be[color=darkred]
            > > > > able to query the db properly, or even connect to it in the way that[/color][/color][/color]
            i[color=blue][color=green][color=darkred]
            > > > want.
            > > > >
            > > > > Thanks in advance
            > > > >
            > > > > Chris
            > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Ron Allen

              #7
              Re: Connecting to a DataBase like i did in VB 6

              Chris,
              Use
              Do While myreader.Read ' assuming I've got the VB syntax for this
              loop
              Dim myVar AS string = myreader.GetStr ing(0) ' for a string at the
              first field returned
              ' also see GetOrdinal to lookup the column #
              from the name
              Dim myInt AS int =
              myreader.GetInt 32(myreader.Get Ordinal("myFiel dName"))
              Loop

              Ron Allen
              "Chris" <xcmharb@lineon e.net> wrote in message
              news:uLWEkcZdEH A.2384@TK2MSFTN GP09.phx.gbl...[color=blue]
              >
              > Thanks Nick thats great, but how do i get at the data?
              >
              > eg.
              >
              > debug.writeline (myreader!name)
              >
              > just throws an error. AAh i know what i wnnt, but not how to sintax it.
              >
              > BTW, all the objects need to be new(ed) on the dims.
              >
              > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
              > news:%23Q$CSNYd EHA.1048@tk2msf tngp13.phx.gbl. ..[color=green]
              > > Something like this:
              > >
              > > Dim mydbConnection As OleDb.OleDbConn ection
              > > mydbConnection. ConnectionStrin g = "c:\mydb.md b"
              > > mydbConnection. Open()
              > >
              > > Dim mydbCommand As OleDb.OleDbComm and
              > > mydbCommand.Con nection = mydbConnection
              > > mydbCommand.Com mandText = "SELECT * FROM MyTable"
              > >
              > > Dim myreader As oleDB.OleDbData Reader
              > >
              > > myreader = mydbCommand.Exe cuteReader
              > >
              > > You can now inspect the myreader object the same way as you did with[/color][/color]
              your[color=blue][color=green]
              > > recordset.
              > >
              > > "Chris" <xcmharb@lineon e.net> wrote in message
              > > news:e5K2avXdEH A.2408@tk2msftn gp13.phx.gbl...[color=darkred]
              > > > Can you give a code example that does teh same as my code below[/color][/color][/color]
              please.[color=blue][color=green][color=darkred]
              > > >
              > > >
              > > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
              > > > news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..
              > > > > Use the OleDdDataAdapte r, Connection and Command controls in[/color][/color][/color]
              winforms[color=blue][color=green]
              > > to[color=darkred]
              > > > > generate the strings that you require for your app. To manipulate[/color][/color]
              > these[color=green][color=darkred]
              > > > > strings programmaticall y try using the stringbuilder class.
              > > > >
              > > > > "Chris" <xcmharb@lineon e.net> wrote in message
              > > > > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...
              > > > > > Hi all,
              > > > > >
              > > > > > I wrote a cool little database program a while back, in VB6, and[/color][/color][/color]
              im[color=blue][color=green][color=darkred]
              > > > > > intending to rewrite it in .net.
              > > > > >
              > > > > > I am new(ish) to .net, but an old hand at VB5/6.
              > > > > >
              > > > > > In VB i would access the mdb file something like this.
              > > > > >
              > > > > > set db=database
              > > > > > set db=opendatabase ("mydb.mdb")
              > > > > > dim rec as recordset
              > > > > > set rec= db.openrecordse t("select name form names")
              > > > > >
              > > > > > while rec.eof=false
              > > > > > debug.write(rec !name)
              > > > rec.movenext
              > > > > > wend
              > > > > >
              > > > > >
              > > > > > How do i do the same in .net, it seems to want me to set up these[/color]
              > > pages[color=darkred]
              > > > > ets,
              > > > > > but i need to create queries and joins on the fly so data can be
              > > > accessed
              > > > > as
              > > > > > the user requests.
              > > > > >
              > > > > > Ive looked in the help, and followed the tutorials, but i cant[/color][/color][/color]
              seem[color=blue]
              > to[color=green][color=darkred]
              > > > be
              > > > > > able to query the db properly, or even connect to it in the way[/color][/color][/color]
              that[color=blue]
              > i[color=green][color=darkred]
              > > > > want.
              > > > > >
              > > > > > Thanks in advance
              > > > > >
              > > > > > Chris
              > > > > >
              > > > > >
              > > > > >
              > > > >
              > > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Chris

                #8
                Re: Connecting to a DataBase like i did in VB 6

                Sorry ron but that does nothing but throw erreors.

                I think i am missing a consecpt here, or .NET has taken DB programing and
                made it so trikey that no one can use it propperly.

                All i wnat is this translated into .NET, ive just complied it and got it
                running in VB6, took me 5mins. In fact it took me less time to write that
                code than it did to write this message. Unlike 2+ days for .NET to do the
                same thing and still no joy.

                here is excatly what i wnat converted, i need the VAR names to remain if
                possible.
                db.mdb has one table (Users) with 2 collums, (Name, Password)


                ///
                dim DB as Database ' i wnat to use the db everywher in the program so i
                only want to open it once.

                sub main()

                set DB = opendatabase("C :\db.mdb") 'open DB

                dim qry as string = "Select * from users;" 'set query
                dim usr as recordset 'create an empty
                record set

                set usr = db.openrecordse t(qry) ' populate record set

                while usr.eof = false ' loop unless
                end of record set is reached
                debug.writeline (usr!Name) 'dump name from
                current record
                debug.writeline (usr!Password) 'dump password from
                current record
                usr.movenext 'move to
                next record
                end while.

                end sub
                ///

                how can this be so diffacult in .NET !!!











                "Ron Allen" <rallen@_nospam _src-us.com> wrote in message
                news:ex8YVRjdEH A.3928@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Chris,
                > Use
                > Do While myreader.Read ' assuming I've got the VB syntax for this
                > loop
                > Dim myVar AS string = myreader.GetStr ing(0) ' for a string at[/color]
                the[color=blue]
                > first field returned
                > ' also see GetOrdinal to lookup the column #
                > from the name
                > Dim myInt AS int =
                > myreader.GetInt 32(myreader.Get Ordinal("myFiel dName"))
                > Loop
                >
                > Ron Allen
                > "Chris" <xcmharb@lineon e.net> wrote in message
                > news:uLWEkcZdEH A.2384@TK2MSFTN GP09.phx.gbl...[color=green]
                > >
                > > Thanks Nick thats great, but how do i get at the data?
                > >
                > > eg.
                > >
                > > debug.writeline (myreader!name)
                > >
                > > just throws an error. AAh i know what i wnnt, but not how to sintax it.
                > >
                > > BTW, all the objects need to be new(ed) on the dims.
                > >
                > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
                > > news:%23Q$CSNYd EHA.1048@tk2msf tngp13.phx.gbl. ..[color=darkred]
                > > > Something like this:
                > > >
                > > > Dim mydbConnection As OleDb.OleDbConn ection
                > > > mydbConnection. ConnectionStrin g = "c:\mydb.md b"
                > > > mydbConnection. Open()
                > > >
                > > > Dim mydbCommand As OleDb.OleDbComm and
                > > > mydbCommand.Con nection = mydbConnection
                > > > mydbCommand.Com mandText = "SELECT * FROM MyTable"
                > > >
                > > > Dim myreader As oleDB.OleDbData Reader
                > > >
                > > > myreader = mydbCommand.Exe cuteReader
                > > >
                > > > You can now inspect the myreader object the same way as you did with[/color][/color]
                > your[color=green][color=darkred]
                > > > recordset.
                > > >
                > > > "Chris" <xcmharb@lineon e.net> wrote in message
                > > > news:e5K2avXdEH A.2408@tk2msftn gp13.phx.gbl...
                > > > > Can you give a code example that does teh same as my code below[/color][/color]
                > please.[color=green][color=darkred]
                > > > >
                > > > >
                > > > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
                > > > > news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..
                > > > > > Use the OleDdDataAdapte r, Connection and Command controls in[/color][/color]
                > winforms[color=green][color=darkred]
                > > > to
                > > > > > generate the strings that you require for your app. To manipulate[/color]
                > > these[color=darkred]
                > > > > > strings programmaticall y try using the stringbuilder class.
                > > > > >
                > > > > > "Chris" <xcmharb@lineon e.net> wrote in message
                > > > > > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...
                > > > > > > Hi all,
                > > > > > >
                > > > > > > I wrote a cool little database program a while back, in VB6, and[/color][/color]
                > im[color=green][color=darkred]
                > > > > > > intending to rewrite it in .net.
                > > > > > >
                > > > > > > I am new(ish) to .net, but an old hand at VB5/6.
                > > > > > >
                > > > > > > In VB i would access the mdb file something like this.
                > > > > > >
                > > > > > > set db=database
                > > > > > > set db=opendatabase ("mydb.mdb")
                > > > > > > dim rec as recordset
                > > > > > > set rec= db.openrecordse t("select name form names")
                > > > > > >
                > > > > > > while rec.eof=false
                > > > > > > debug.write(rec !name)
                > > > > rec.movenext
                > > > > > > wend
                > > > > > >
                > > > > > >
                > > > > > > How do i do the same in .net, it seems to want me to set up[/color][/color][/color]
                these[color=blue][color=green][color=darkred]
                > > > pages
                > > > > > ets,
                > > > > > > but i need to create queries and joins on the fly so data can be
                > > > > accessed
                > > > > > as
                > > > > > > the user requests.
                > > > > > >
                > > > > > > Ive looked in the help, and followed the tutorials, but i cant[/color][/color]
                > seem[color=green]
                > > to[color=darkred]
                > > > > be
                > > > > > > able to query the db properly, or even connect to it in the way[/color][/color]
                > that[color=green]
                > > i[color=darkred]
                > > > > > want.
                > > > > > >
                > > > > > > Thanks in advance
                > > > > > >
                > > > > > > Chris
                > > > > > >
                > > > > > >
                > > > > > >
                > > > > >
                > > > > >
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Ron Allen

                  #9
                  Re: Connecting to a DataBase like i did in VB 6

                  Chris,
                  It doesn't seem that difficult to me. In C# I'd write

                  void main() // or some other function called at startup.
                  {
                  string connStr = @"Provider=Micr osoft.Jet.OLEDB .4.0;Data
                  Source=C:\db.md b;Mode=Share Deny None;";
                  OleDbConnection db = new OleDbConnection (connStr)
                  OleDbCommand cmd = new OleDbCommand("S elect Name, Password FROM Users",
                  db);
                  _db.Open();
                  OleDbDataReader rdr = cmd.ExecuteRead er();
                  while (rdr.Read())
                  {
                  System.Diagnost ics.Debug.Write Line(rdr.GetStr ing(0));
                  System.Diagnost ics.Debug.Write Line(rdr.GetStr ing(1));
                  }
                  _db.Close(); // close the connection
                  }

                  Note that to use the db variable in other modules you will have to make it
                  public and specific to the module and pass the class it is in to those
                  programs. Also make sure that your main doesn't just return after writing
                  these as that will cause the program to exit. I do this by having my own
                  class for doing database manipulation. I pass in an open connection or a
                  database name/server nam (filename for OleDb) and then do all the
                  manipulation there.

                  You may want to visit microsoft.publi c.dotnet.framew ork.adonet as that
                  is dedicated to ADO.NET questions.

                  Also the book by David Sceppa "ADO.NET Core Reference" is quite good and
                  has a lot of examples in both C# and VB.NET

                  Ron Allen

                  "Chris" <xcmharb@lineon e.net> wrote in message
                  news:u$RYd2jdEH A.3732@TK2MSFTN GP11.phx.gbl...[color=blue]
                  > Sorry ron but that does nothing but throw erreors.
                  >
                  > I think i am missing a consecpt here, or .NET has taken DB programing and
                  > made it so trikey that no one can use it propperly.
                  >
                  > All i wnat is this translated into .NET, ive just complied it and got it
                  > running in VB6, took me 5mins. In fact it took me less time to write that
                  > code than it did to write this message. Unlike 2+ days for .NET to do the
                  > same thing and still no joy.
                  >
                  > here is excatly what i wnat converted, i need the VAR names to remain if
                  > possible.
                  > db.mdb has one table (Users) with 2 collums, (Name, Password)
                  >
                  >
                  > ///
                  > dim DB as Database ' i wnat to use the db everywher in the program so i
                  > only want to open it once.
                  >
                  > sub main()
                  >
                  > set DB = opendatabase("C :\db.mdb") 'open DB
                  >
                  > dim qry as string = "Select * from users;" 'set query
                  > dim usr as recordset 'create an[/color]
                  empty[color=blue]
                  > record set
                  >
                  > set usr = db.openrecordse t(qry) ' populate record set
                  >
                  > while usr.eof = false ' loop[/color]
                  unless[color=blue]
                  > end of record set is reached
                  > debug.writeline (usr!Name) 'dump name from
                  > current record
                  > debug.writeline (usr!Password) 'dump password from
                  > current record
                  > usr.movenext 'move to
                  > next record
                  > end while.
                  >
                  > end sub
                  > ///
                  >
                  > how can this be so diffacult in .NET !!!
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  > "Ron Allen" <rallen@_nospam _src-us.com> wrote in message
                  > news:ex8YVRjdEH A.3928@TK2MSFTN GP09.phx.gbl...[color=green]
                  > > Chris,
                  > > Use
                  > > Do While myreader.Read ' assuming I've got the VB syntax for this
                  > > loop
                  > > Dim myVar AS string = myreader.GetStr ing(0) ' for a string at[/color]
                  > the[color=green]
                  > > first field returned
                  > > ' also see GetOrdinal to lookup the column #
                  > > from the name
                  > > Dim myInt AS int =
                  > > myreader.GetInt 32(myreader.Get Ordinal("myFiel dName"))
                  > > Loop
                  > >
                  > > Ron Allen
                  > > "Chris" <xcmharb@lineon e.net> wrote in message
                  > > news:uLWEkcZdEH A.2384@TK2MSFTN GP09.phx.gbl...[color=darkred]
                  > > >
                  > > > Thanks Nick thats great, but how do i get at the data?
                  > > >
                  > > > eg.
                  > > >
                  > > > debug.writeline (myreader!name)
                  > > >
                  > > > just throws an error. AAh i know what i wnnt, but not how to sintax[/color][/color][/color]
                  it.[color=blue][color=green][color=darkred]
                  > > >
                  > > > BTW, all the objects need to be new(ed) on the dims.
                  > > >
                  > > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
                  > > > news:%23Q$CSNYd EHA.1048@tk2msf tngp13.phx.gbl. ..
                  > > > > Something like this:
                  > > > >
                  > > > > Dim mydbConnection As OleDb.OleDbConn ection
                  > > > > mydbConnection. ConnectionStrin g = "c:\mydb.md b"
                  > > > > mydbConnection. Open()
                  > > > >
                  > > > > Dim mydbCommand As OleDb.OleDbComm and
                  > > > > mydbCommand.Con nection = mydbConnection
                  > > > > mydbCommand.Com mandText = "SELECT * FROM MyTable"
                  > > > >
                  > > > > Dim myreader As oleDB.OleDbData Reader
                  > > > >
                  > > > > myreader = mydbCommand.Exe cuteReader
                  > > > >
                  > > > > You can now inspect the myreader object the same way as you did with[/color]
                  > > your[color=darkred]
                  > > > > recordset.
                  > > > >
                  > > > > "Chris" <xcmharb@lineon e.net> wrote in message
                  > > > > news:e5K2avXdEH A.2408@tk2msftn gp13.phx.gbl...
                  > > > > > Can you give a code example that does teh same as my code below[/color]
                  > > please.[color=darkred]
                  > > > > >
                  > > > > >
                  > > > > > "Nick Wilton" <nickDOTwiltonA ThtzDOTbiz> wrote in message
                  > > > > > news:%23KfkosXd EHA.3728@TK2MSF TNGP09.phx.gbl. ..
                  > > > > > > Use the OleDdDataAdapte r, Connection and Command controls in[/color]
                  > > winforms[color=darkred]
                  > > > > to
                  > > > > > > generate the strings that you require for your app. To[/color][/color][/color]
                  manipulate[color=blue][color=green][color=darkred]
                  > > > these
                  > > > > > > strings programmaticall y try using the stringbuilder class.
                  > > > > > >
                  > > > > > > "Chris" <xcmharb@lineon e.net> wrote in message
                  > > > > > > news:OSNebhXdEH A.1692@tk2msftn gp13.phx.gbl...
                  > > > > > > > Hi all,
                  > > > > > > >
                  > > > > > > > I wrote a cool little database program a while back, in VB6,[/color][/color][/color]
                  and[color=blue][color=green]
                  > > im[color=darkred]
                  > > > > > > > intending to rewrite it in .net.
                  > > > > > > >
                  > > > > > > > I am new(ish) to .net, but an old hand at VB5/6.
                  > > > > > > >
                  > > > > > > > In VB i would access the mdb file something like this.
                  > > > > > > >
                  > > > > > > > set db=database
                  > > > > > > > set db=opendatabase ("mydb.mdb")
                  > > > > > > > dim rec as recordset
                  > > > > > > > set rec= db.openrecordse t("select name form names")
                  > > > > > > >
                  > > > > > > > while rec.eof=false
                  > > > > > > > debug.write(rec !name)
                  > > > > > rec.movenext
                  > > > > > > > wend
                  > > > > > > >
                  > > > > > > >
                  > > > > > > > How do i do the same in .net, it seems to want me to set up[/color][/color]
                  > these[color=green][color=darkred]
                  > > > > pages
                  > > > > > > ets,
                  > > > > > > > but i need to create queries and joins on the fly so data can[/color][/color][/color]
                  be[color=blue][color=green][color=darkred]
                  > > > > > accessed
                  > > > > > > as
                  > > > > > > > the user requests.
                  > > > > > > >
                  > > > > > > > Ive looked in the help, and followed the tutorials, but i cant[/color]
                  > > seem[color=darkred]
                  > > > to
                  > > > > > be
                  > > > > > > > able to query the db properly, or even connect to it in the[/color][/color][/color]
                  way[color=blue][color=green]
                  > > that[color=darkred]
                  > > > i
                  > > > > > > want.
                  > > > > > > >
                  > > > > > > > Thanks in advance
                  > > > > > > >
                  > > > > > > > Chris
                  > > > > > > >
                  > > > > > > >
                  > > > > > > >
                  > > > > > >
                  > > > > > >
                  > > > > >
                  > > > > >
                  > > > >
                  > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Cor Ligthert

                    #10
                    Re: Connecting to a DataBase like i did in VB 6

                    Chris,

                    I am really stumbled, I made a sample exactly as yours however now in VBNet
                    way and you even did not look to it.

                    Cor


                    Comment

                    Working...