Split from - http://www.daniweb.com/forums/thread94883.html

hi i have the button click event

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Postmyadd\App_Data\postmyad.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

myConn.Open();
string strqry = "Insert into advertisements values (" + TextBox1.Text +")"; 

SqlCommand myCom = new SqlCommand(strqry, myConn);
int numrow = myCom.ExecuteNonQuery();
myConn.Close();
    }

but when i bebug i get the error saying unrecognized escape sequence '\'.

Recommended Answers

All 2 Replies

Welcome to Daniweb.

Firstly, read the forum rules. For easy readability, always wrap programming code within posts in code blocks.

@-quoting is that escape sequences are not processed.

myConn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Postmyadd\App_Data\postmyad.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

Try using the following code:

SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\\Postmyadd\\App_Data\\postmyad.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.