Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS1009: Unrecognized escape sequence

Tags:

c#

asp.net

I have created a site with the following connection string.

I am getting the following error message any help would be really appreciated.

Compiler Error Message: CS1009: Unrecognized escape sequence
Line 21: ad.DataFile = "D:\Hosting\9372580\html\pearl\Pearl.mdb";

my codes:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class html_Show_Projinfo : System.Web.UI.Page
{
    OleDbCommand cmd;
    OleDbConnection con = new OleDbConnection();
    OleDbDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        con.ConnectionString = ConfigurationManager.ConnectionStrings["pearl"].ToString();
        cmd = new OleDbCommand("Select * from Pearl_Projects where ProjectId=" + id, con);
        con.Open();
        rd = cmd.ExecuteReader();
        string ns;
        while (rd.Read())
        {
            Label2.Text = rd["ProjectName"].ToString();
            ns = rd["Shortdes"].ToString();
            if (ns.Length > 541)
            {
                Label1.Text = ns.Substring(0, 541);
            }
            else
            {
                Label1.Text = ns.Substring(0, ns.Length);
            }            

            Label3.Text = rd["Description"].ToString();
            Label4.Text = rd["location"].ToString();
        }
        rd.Close();
        con.Close();

        //con.Open();
        //cmd = new OleDbCommand("Select ProjectId from Pearl_ProjectDetails where DetailId=" + id, con);
        //int j = Convert.ToInt32(cmd.ExecuteScalar());
        //con.Close();

        //con.Open();
        //cmd = new OleDbCommand("Select ProjectName from Pearl_Projects where ProjectId=" + j, con);
        //Label1.Text = cmd.ExecuteScalar().ToString();
        //con.Close();
        if (Label4.Text == "")
        {
            Label4.Visible = false;
            Label5.Visible = false;
        }
        else
        {
            Label4.Visible = true;
            Label5.Visible = true;
        }
        AccessDataSource ad = new AccessDataSource();
        ad.DataFile = "D:\Hosting\9372580\html\pearl\Pearl.mdb";
        ad.SelectCommand = "SELECT top 3 ProjectId,ProjectName,Status FROM [Pearl_Projects] where Status=no Order by ProjectId Desc";
        DataList1.DataSource = ad;
        DataList1.DataBind();

        AccessDataSource ad1 = new AccessDataSource();
        ad1.DataFile = "D:\Hosting\9372580\html\pearl\Pearl.mdb";
        ad1.SelectCommand = "SELECT top 3 ProjectId,ProjectName,Status FROM [Pearl_Projects] where Status=yes Order by ProjectId Desc";
        DataList2.DataSource = ad1;
        DataList2.DataBind();
    }
}
like image 269
Efe Avatar asked Jul 03 '13 19:07

Efe


2 Answers

escape those \ in lines like the following

ad.DataFile = "D:\Hosting\9372580\html\pearl\Pearl.mdb";

you can either manually escape them all like so

ad.DataFile = "D:\\Hosting\\9372580\\html\\pearl\\Pearl.mdb";

or you can make it a literal string

ad.DataFile = @"D:\Hosting\9372580\html\pearl\Pearl.mdb";

the character '\' begins what is called an "Escape Sequence", and it essentially that you're using 2 characters to represent 1(special) character.

for instance, \n is a newline character, \0 is null, and \\ is \

like image 93
Sam I am says Reinstate Monica Avatar answered Nov 08 '22 02:11

Sam I am says Reinstate Monica


You need to use "\\" as "\" is an escape sequence.
http://msdn.microsoft.com/en-us/library/44ezxxy3(v=vs.80).aspx

like image 2
AM_Hawk Avatar answered Nov 08 '22 01:11

AM_Hawk