CS1009:无法识别的转义序列 [英] CS1009: Unrecognized escape sequence
问题描述
我已经创建了下面的连接字符串的网站。
我收到以下错误消息的任何帮助将是非常美联社preciated。
编译器错误信息:CS1009:无法识别的转义序列结果 21行:ad.DataFile =D:\\主机\\ 9372580 \\ HTML \\珍珠\\ Pearl.mdb;
我的codeS:
使用系统;
使用System.Data这;
使用System.Configuration;
System.Collections中使用;
使用的System.Web;
使用System.Web.Security;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.Data.OleDb;公共部分类html_Show_Projinfo:System.Web.UI.Page
{
OleDbCommand的CMD;
OleDbConnection的CON =新的OleDbConnection();
OleDbDataReader次;
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
INT ID = Convert.ToInt32(的Request.QueryString [身份证]);
con.ConnectionString = ConfigurationManager.ConnectionStrings [珍珠]的ToString()。
CMD =新的OleDbCommand(从Pearl_Projects选择*其中专案编号=+ ID,CON);
con.Open();
RD = cmd.ExecuteReader();
串纳秒;
而(rd.Read())
{
Label2.Text = RD [项目名]的ToString()。
NS = RD [Shortdes]的ToString()。
如果(ns.Length> 541)
{
Label1.Text = ns.Substring(0,541);
}
其他
{
Label1.Text = ns.Substring(0,ns.Length);
} Label3.Text = RD [说明]的ToString()。
Label4.Text = RD [所在地]的ToString()。
}
rd.Close();
con.Close(); //con.Open();
// CMD =新的OleDbCommand(从Pearl_ProjectDetails选择专案编号,其中DetailId =+ ID,CON);
// INT J = Convert.ToInt32(cmd.ExecuteScalar());
//con.Close(); //con.Open();
// CMD =新的OleDbCommand(从Pearl_Projects选择项目名,其中专案编号=+ J,CON);
//Label1.Text = cmd.ExecuteScalar()的ToString()。
//con.Close();
如果(Label4.Text ==)
{
Label4.Visible = FALSE;
Label5.Visible = FALSE;
}
其他
{
Label4.Visible = TRUE;
Label5.Visible = TRUE;
}
广告的AccessDataSource =新的AccessDataSource();
ad.DataFile =D:\\主机\\ 9372580 \\ HTML \\珍珠\\ Pearl.mdb
ad.SelectCommand =SELECT前3名专案编号,项目名,状态从[Pearl_Projects]其中状态=由专案编号说明没有秩序;
DataList1.DataSource =广告;
DataList1.DataBind(); AD1的AccessDataSource =新的AccessDataSource();
ad1.DataFile =D:\\主机\\ 9372580 \\ HTML \\珍珠\\ Pearl.mdb
ad1.SelectCommand =SELECT前3名专案编号,项目名,状态从[Pearl_Projects]其中状态= yes此专案编号倒序
DataList2.DataSource = AD1;
DataList2.DataBind();
}
}
在般的线条逃生者 \\
以下
ad.DataFile =D:\\主机\\ 9372580 \\ HTML \\珍珠\\ Pearl.mdb
您可以手动逃脱他们都像这样
ad.DataFile =D:\\\\ \\\\托管\\\\ 9372580 HTML \\\\ \\\\珍珠Pearl.mdb
或者你可以把它一个字符串
ad.DataFile = @D:\\主机\\ 9372580 \\ HTML \\珍珠\\ Pearl.mdb
字符'\\'
开始所谓基本上转义序列,而且您正在使用2个字符重新present 1(特殊)字符。
例如, \\ n
是一个换行符, \\ 0
为空,而 \\\\
是 \\
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();
}
}
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 \
这篇关于CS1009:无法识别的转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!