View Full Version : OleDbConnection error

Brett Bretterso
11-15-2005, 03:56 PM
I'm new to C# and I'm trying to use an OleDbConnection to connect to an access database. I've done it before in VB.NET, and tried translating the code to C#. I do have the namespace required to do it (using System.Data.OleDb;) and asp.net has no problems with that. Instead it's giving me an error when I try to declare my connection. Here's the relevant parts of the code.

string myConnString= "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + server.mappath("pizza.mdb");
OleDbConnection cn = New OleDbConnection(myConnString);

string qryStr="select * from pizza";

try {
OleDbCommand cmd = New OleDbCommand(qryStr, cn);

OleDbDataReader rdr = cmd.ExecuteReader();
int count=0;
while (rdr.Read()){
if (count==1){
else {

catch (Exception ex){
Response.Write("An error occurred: ");

The red line is the one that's giving me the error, but all it says is Compiler Error Message: CS1002: ; expected. From what I can see there's nothing wrong with that line.

Any help would be appreciated.

Brett Bretterson

Brett Bretterso
11-15-2005, 04:08 PM
I found the problem. C# is case sensitive while VB.NET is not. I changed server.mappath to Server.MapPath and it started working.

Brett Bretterso
11-15-2005, 04:10 PM
okay, that was a different problem. I'm still getting the same error. It just worked when I was testing something else.

So, I still need help, but the problem isn't Server.MapPath

Brett Bretterson

Brett Bretterso
11-15-2005, 04:11 PM
Okay, now I fixed it. Once again the problem was case sensitivity. I had New instead of new