0

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 '\'.

Edited by __avd: Split into a new thread. Added [code] tags.

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by vinnijain
0

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";

Edited by happygeek: fixed formatting

0

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";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.