PDA

Click to See Complete Forum and Search --> : ADOConnection Problems


OrderAdmin
Oct 8th, 2002, 03:33 AM
VB.NET
-----------------------------------------------------
I can't access to my access database via ado.net.
When I type in :
ADOConnection adoConnection = new ADOConnection()
the keyword ADOConnection is underlined, and can't be found!!
So, what shall I do?
to import something??
I've looked at so many examples of database accessing with ado.net in the internet, but nothing works!!
Perhaps you could give me some examples, how i could access to an access db called login, with one table 'login' and there i want to update the field username where id = 3, for example!!!
thx for your help!

Musician
Oct 8th, 2002, 03:30 PM
well this is a vb.net forum so I'll be giving you the vb.net version of the code:-

dim conn as new system.data.oledb.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=fullpathtologin.mdb")
dim cmd as new system.data.oledb.oledbcommand
cmd.connection = conn
cmd.commandtype = CommandType.Text
cmd.commandtext = "update login set username='blah' where id=3"
try
conn.open
cmd.executenonquery
finally
conn.close
end try

or to return data for display use an oledbdatareader:-

dim conn as new system.data.oledb.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=fullpathtologin.mdb")
dim cmd as new system.data.oledb.oledbcommand
dim dr as system.data.oledb.oledbdatareader
cmd.connection = conn
cmd.commandtype = CommandType.Text
cmd.commandtext = "select password from login where username='blah'"
try
conn.open
dr = cmd.executereader
if dr.getvalue(0).tostring = PasswordTextBox.text then
messagebox.show("Login Successful!")
else
messagebox.show("Invalid Password!")
end if
finally
conn.close
end try