Error with OleDb not found
-
Hello I have a problem with the following code. It gives an error saying that the OleDb could not be found. I have included using System.OleDb at the top of my form. But still get the error. [code=vb] cnnTeacher.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IBS Library System\LibrarySystem.mdb;Persist Security Info=False"; OleDbCommand cmdTeacher = cnnTeacher.CreateCommand(); cmdTeacher.CommandText = "Select * From Teacher Where TeacherID = txtIDNumber.text"; cmdTeacher.Parameters.Add("ID", OleDb.VarWChar, 40).Value = txtIDNumber.Text; //OleDb could not be found OleDbDataAdapter daTeacher = new OleDbDataAdapter(cmdTeacher); OleDbCommandBuilder cbTeacher = new OleDbCommandBuilder(daTeacher); daTeacher.Fill(dtTeacher); [/code] Many thanks in advance, Steve
-
Hello I have a problem with the following code. It gives an error saying that the OleDb could not be found. I have included using System.OleDb at the top of my form. But still get the error. [code=vb] cnnTeacher.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IBS Library System\LibrarySystem.mdb;Persist Security Info=False"; OleDbCommand cmdTeacher = cnnTeacher.CreateCommand(); cmdTeacher.CommandText = "Select * From Teacher Where TeacherID = txtIDNumber.text"; cmdTeacher.Parameters.Add("ID", OleDb.VarWChar, 40).Value = txtIDNumber.Text; //OleDb could not be found OleDbDataAdapter daTeacher = new OleDbDataAdapter(cmdTeacher); OleDbCommandBuilder cbTeacher = new OleDbCommandBuilder(daTeacher); daTeacher.Fill(dtTeacher); [/code] Many thanks in advance, Steve
I have just spent the last month fighting with OleDb, so you have my sympathy! :) 1) Have you tried "using System.Data.OleDb;" instead of "System.OleDb"? (If you're using VB.NET, doesn't it use the term "Imports" instead of "using"?) 2) Make sure the driver (in your case the MS Jet OleDb driver dll) has been installed on your system. 3) I have read that if you use a DataAdapter you do not need to do an explicit open on the connection (i.e. cnnTeacher.Open()), but if all else fails, I would give it a try. Hope this helps!
-
I have just spent the last month fighting with OleDb, so you have my sympathy! :) 1) Have you tried "using System.Data.OleDb;" instead of "System.OleDb"? (If you're using VB.NET, doesn't it use the term "Imports" instead of "using"?) 2) Make sure the driver (in your case the MS Jet OleDb driver dll) has been installed on your system. 3) I have read that if you use a DataAdapter you do not need to do an explicit open on the connection (i.e. cnnTeacher.Open()), but if all else fails, I would give it a try. Hope this helps!
-
Thanks for your help I am using: using System.Data.OleDb; Opening the connection is not a problem. But l am not sure about this OleDb driver dll, how would l know that I have it installed on my computer. I hope you can help. Thanks, Steve
To determine if a driver is installed on your system, go to: Control Panel, Administrative Tools, Data Sources (ODBC), Select the "Drivers" tab. If the driver is not listed, your best bet would be to download and register the driver from Microsoft's site. But, I think the problem could be punctuation ... there needs to be a semi-colon (";") on the inside of the ending quote mark of the connection string (as well as one outside the quote mark to end the command line). For example: sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;"; If you are still having trouble, I would look at the "OleDb.VarWChar" variable in the Parameters statement where the error is occurring. I have not dealt with parameters, but I might hazard a guess that the the OleDb needs to be qualified (i.e. System.Data.OleDb.OleDbType.VarWChar). I have had items come up in intellisense, but did not run until qualified. Hope this helps!
-
To determine if a driver is installed on your system, go to: Control Panel, Administrative Tools, Data Sources (ODBC), Select the "Drivers" tab. If the driver is not listed, your best bet would be to download and register the driver from Microsoft's site. But, I think the problem could be punctuation ... there needs to be a semi-colon (";") on the inside of the ending quote mark of the connection string (as well as one outside the quote mark to end the command line). For example: sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;"; If you are still having trouble, I would look at the "OleDb.VarWChar" variable in the Parameters statement where the error is occurring. I have not dealt with parameters, but I might hazard a guess that the the OleDb needs to be qualified (i.e. System.Data.OleDb.OleDbType.VarWChar). I have had items come up in intellisense, but did not run until qualified. Hope this helps!
Hello, Thanks for your help. I managed to find the answer. I don't need the line to add parameters. So l deleted it and made a few changes and now it works fine. Below is the correct code for your own review.
cnnTeacher.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IBS Library System\LibrarySystem.mdb;Persist Security Info=False"; OleDbCommand cmdTeacher = cnnTeacher.CreateCommand(); cmdTeacher.CommandText = "Select * From Teacher Where TeacherID = '" + txtIDNumber.Text + "' "; OleDbDataAdapter daTeacher = new OleDbDataAdapter(cmdTeacher); OleDbCommandBuilder cbTeacher = new OleDbCommandBuilder(daTeacher); daTeacher.Fill(dtTeacher)
steve