You can just use Replace to convert
"\"
to
"\\"
like this
public string FilePath
{
get{return textBox1.Text.Trim();}
set { this.textBox1.Text = value.Replace(@"\", @"\\"); }
}
Hope this Helps
Here is the code for the whole form I used for testing :
public string FilePath
{
get{return textBox1.Text.Trim();}
set { this.textBox1.Text = value.Replace(@"\", @"\\"); }
}
public Form1()
{
InitializeComponent();
}
public void Save()
{
using (MySqlConnection con = new MySqlConnection("server=localhost;User Id=xxxx;password=xxxx;database=xxxx"))
{
MySqlCommand cmdSave = new MySqlCommand("UPDATE"
+ " myTable"
+ " SET"
+ " FilePath = @FilePath"
+ " WHERE"
+ " myClassID = @myClassID", con);
cmdSave.Parameters.AddWithValue("@myClassID", 1);
cmdSave.Parameters.AddWithValue("@FilePath", FilePath);
con.Open();
int rowsAffected = cmdSave.ExecuteNonQuery();
}
}
private void button1_Click(object sender, EventArgs e)
{
Save();
}
and it all works as expected.
Good Luck!!