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=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\db.mdb;Mode=Share Deny None;";
OleDbConnection db = new OleDbConnection(connStr)
OleDbCommand cmd = new OleDbCommand("Select Name, Password FROM Users",
db);
_db.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
System.Diagnostics.Debug.WriteLine(rdr.GetString(0));
System.Diagnostics.Debug.WriteLine(rdr.GetString(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.public.dotnet.framework.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" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> 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.openrecordset(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:(E-Mail Removed)...
> > Chris,
> > Use
> > Do While myreader.Read ' assuming I've got the VB syntax for this
> > loop
> > Dim myVar AS string = myreader.GetString(0) ' for a string at
> the
> > first field returned
> > ' also see GetOrdinal to lookup the column #
> > from the name
> > Dim myInt AS int =
> > myreader.GetInt32(myreader.GetOrdinal("myFieldName"))
> > Loop
> >
> > Ron Allen
> > "Chris" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > 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" <nickDOTwiltonAThtzDOTbiz> wrote in message
> > > news:%23Q$(E-Mail Removed)...
> > > > Something like this:
> > > >
> > > > Dim mydbConnection As OleDb.OleDbConnection
> > > > mydbConnection.ConnectionString = "c:\mydb.mdb"
> > > > mydbConnection.Open()
> > > >
> > > > Dim mydbCommand As OleDb.OleDbCommand
> > > > mydbCommand.Connection = mydbConnection
> > > > mydbCommand.CommandText = "SELECT * FROM MyTable"
> > > >
> > > > Dim myreader As oleDB.OleDbDataReader
> > > >
> > > > myreader = mydbCommand.ExecuteReader
> > > >
> > > > You can now inspect the myreader object the same way as you did with
> > your
> > > > recordset.
> > > >
> > > > "Chris" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > Can you give a code example that does teh same as my code below
> > please.
> > > > >
> > > > >
> > > > > "Nick Wilton" <nickDOTwiltonAThtzDOTbiz> wrote in message
> > > > > news:%(E-Mail Removed)...
> > > > > > Use the OleDdDataAdapter, Connection and Command controls in
> > winforms
> > > > to
> > > > > > generate the strings that you require for your app. To
manipulate
> > > these
> > > > > > strings programmatically try using the stringbuilder class.
> > > > > >
> > > > > > "Chris" <(E-Mail Removed)> wrote in message
> > > > > > news:(E-Mail Removed)...
> > > > > > > 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.openrecordset("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
> > > > 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
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|