Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OleDbConnection error

    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.

    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";
    		
    		cn.Open();
    		try {
    			OleDbCommand cmd = New OleDbCommand(qryStr, cn);
    			
    			OleDbDataReader rdr = cmd.ExecuteReader();
    			int count=0;
    			while (rdr.Read()){
    				count=1;
    			}		
    			rdr.Close();
    			if (count==1){
    			}
    			else {
    			}
    			
    		}
    		catch (Exception ex){
    			Response.Write("An error occurred: ");
    			Response.Write(ex);
    		}
    
    		cn.Close();
    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

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found the problem. C# is case sensitive while VB.NET is not. I changed server.mappath to Server.MapPath and it started working.

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, now I fixed it. Once again the problem was case sensitivity. I had New instead of new


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •