locked
SqlConnection Error( Unrecognized escape sequence ) RRS feed

  • Question

  • User1793335744 posted

     Hi I have the same error but with Accessconnection.. I am trying to do the same thing (Adding to access DB from a text box using an add button).. So I placed the following code into the Add button:

     protected void btnAdd_Click(object sender, EventArgs e)
        {
            OleDbConnection = cn;
            OleDbCommand = cmd;

           cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");
           cmd = new OleDbCommand;    
                cmd.CommandText = "insert into students (win) values (" & this.TRACK2.Text & ");
                cmd.Connection = cn;
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
                cmd.Dispose();
            
            cn.Dispose();
            
        }

    But iam getting the same error.. pls help

    Thursday, June 11, 2009 4:12 PM

Answers

  • User-284360669 posted

    this....      

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");

     

    should be

     

      cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AccessDB\\db1.mdb;User Id=admin;Password=;");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2009 4:26 PM
  • User1485238302 posted

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");

    Try this: 

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AccessDB\\db1.mdb;User Id=admin;Password=;");
    or 
    cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");
    
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2009 4:27 PM

All replies

  • User-284360669 posted

    this....      

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");

     

    should be

     

      cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AccessDB\\db1.mdb;User Id=admin;Password=;");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2009 4:26 PM
  • User1485238302 posted

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");

    Try this: 

    cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AccessDB\\db1.mdb;User Id=admin;Password=;");
    or 
    cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessDB\db1.mdb;User Id=admin;Password=;");
    
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2009 4:27 PM
  • User-1199946673 posted

    Please don't ask the same question in multiple forums!

    http://forums.asp.net/t/1434406.aspx

     

    Thursday, June 11, 2009 4:34 PM