By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Database connection help

jamesd0142
100+
P: 469
connecting to a ms access database using vb express 2005

Expand|Select|Wrap|Line Numbers
  1. Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=c:\Users\Users.mdb"
  2.         'Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & FileName
  3.  
  4.         Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
  5.  
  6.         Dim queryString As String = "Select Login from TBLUsers"
  7.         Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
  8.         dbCommand.CommandText = queryString
  9.         dbCommand.Connection = dbConnection
  10.  
  11.         Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
  12.         dataAdapter.SelectCommand = dbCommand
  13.         Dim dataSet As System.Data.DataSet = New System.Data.DataSet
  14.         dataAdapter.Fill(dataSet)
  15.  
  16.         DGV1.DataSource = dataSet
  17.  
when i click a button the above code executes, i have a datagrid called DGV1, can any1 help as to why this is not working.

I get no error at all, and the filepath is correct and also the table has values.
Dec 12 '07 #1
Share this Question
Share on Google+
6 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

Declare Objects as: and check

Expand|Select|Wrap|Line Numbers
  1. Dim dbConnection As New System.Data.OleDb.OleDbConnection(connectionString)
  2. Dim dbCommand As New System.Data.OleDb.OleDbCommand
  3. Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter
  4.  


Regards
Veena
Dec 12 '07 #2

jamesd0142
100+
P: 469
ok so now im using:

Expand|Select|Wrap|Line Numbers
  1.   Dim connectionstring As String
  2.         connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=c:\Users\Users.mdb"
  3.  
  4.         Dim dbConnection As New System.Data.OleDb.OleDbConnection(connectionstring)
  5.  
  6.         Dim queryString As String = "Select Login from TBLUsers"
  7.         Dim dbCommand As New System.Data.OleDb.OleDbCommand
  8.         dbCommand.CommandText = queryString
  9.         dbCommand.Connection = dbConnection
  10.  
  11.         Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter
  12.         dataAdapter.SelectCommand = dbCommand
  13.         Dim dataSet As System.Data.DataSet = New System.Data.DataSet
  14.         dataAdapter.Fill(dataSet)
  15.  
  16.         DGV1.DataSource = dataSet
  17.  
Still no errors and yet Datagrid stays empty

Cheers James
Dec 12 '07 #3

QVeen72
Expert 100+
P: 1,445
Hi,

Try this Code :

Expand|Select|Wrap|Line Numbers
  1. Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  2.         Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  3.         '
  4.         Dim da As System.Data.OleDb.OleDbDataAdapter
  5.         Dim oDS As New System.Data.DataSet
  6.         '
  7.         Dim strSQL As String ="Select * From MyTable"
  8.         da = New OleDbDataAdapter(strsql, oConn)
  9.         da.Fill(oDS, "Table1")
  10.         DGV1.DataSource = oDS.Tables("Table1").DefaultView
  11.         DGV1.Refresh()
  12.         '
  13.         da = Nothing
  14.         oDS = Nothing
  15.         oConn = Nothing
  16.  

Regards
Veena
Dec 12 '07 #4

jamesd0142
100+
P: 469
AMAZING!

Thanks Alot!

James
Dec 12 '07 #5

jamesd0142
100+
P: 469
How could i now edit a field in the database?

for example:

sql -

update TBLUsers set password = "123" where login = "durbinj"


i tried this
Expand|Select|Wrap|Line Numbers
  1.    Dim Conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Users.mdb")
  2.     Conn.open()
  3.     Dim SQLstr As String = "update TBLUsers set password = '123' where login = 'durbinj'"
  4.     Dim Command As New OleDb.OleDbCommand(SQLstr, Conn)
  5.     Dim icount As Integer = Command.ExecuteNonQuery
  6.  
but i get error on line "conn.open()"

"declaration expected"
cheers James
Dec 12 '07 #6

jamesd0142
100+
P: 469
ok this is not an issue anymore, cheers
Dec 12 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.