I am building a database in c# using visual studio. I am trying to pass a paragraph of text from the site into sql server database. However types of punctuation are being read as special characters such as ' or ". Would anyone be able to tell me how to replace these so that they will successfully pass into the database? Below is an example of my code.
DataAccess layer
public static String createNewPresident(string strTitle, string strText, string strImageUrl)
{
SqlConnection conn = openConnection();//Open Connection
string strSQL = "INSERT INTO President(PresidentTitle, " +
" PresidentDescription, " + " PresidentImageURL) " +
" VALUES('" + strTitle + "' , '" + strText + "' , '" + strImageUrl + "')";//Insert Into Statement
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.ExecuteNonQuery();
closeConnection(conn);//Close Connection
return strTitle;//Display Success
}//createNewPresident
Business Layer Logic
private string strTitle, strText, strImageurl;
public Add_New_President_Class(string nTitle, string nText, string nImageurl)
{
strTitle = nTitle;
strText = nText;
strImageurl = nImageurl;
}//constructor
public void createNewPresident()
{
String retTitle = DataAccess.createNewPresident(strTitle, strText, strImageurl);
strTitle = retTitle;
}
public string getTitle()
{
return strTitle;
}
and c# code behind page
protected void btnAddNewPresident_Click(object sender, EventArgs e)
{
String imageName = fuImagePresident.FileName;
fuImagePresident.PostedFile.SaveAs(Server.MapPath("../Home_Images/president.jpg"));
String url = "../Home_Images/president.jpg";
String textReplaced;
textReplaced = txtPresidentText.Text.Replace("\n", "<br />");
Add_New_President_Class newPresident = new Add_New_President_Class(txtPresidentTitle.Text, textReplaced, url);
newPresident.createNewPresident();
Session["newpresident"] = newPresident;
txtPresidentTitle.Text = "";
txtPresidentText.Text = "";
Response.Write("<script>window.alert('A news president has been added')</script>");
}
Any help would be greatly appreciated