0

I have a query like this:

sql = "Select * From T_ExhibitorLocation 
        where F_ExhibitionCode='" & Cmb_Exhibition.SelectedValue.ToString & "' 
          and F_ExhibitorCode='" & Trim(Txt_ExhibitorID.Text) & "' 
          and F_Site='" & cmb_Site.SelectedValue.ToString &` "'"

Some time my F_site name come with apostrophe, example like this 'Artist's Shell'. So this time how I can save this name with apostrophe ?? thanks in advance

Saagar Elias Jacky
  • 2,684
  • 2
  • 14
  • 28
jase mhi
  • 83
  • 1
  • 1
  • 7

1 Answers1

2

Like Pluntonix said in his comment always try to avoid building sql command in this way..try the below way if you can

var command = new SqlCommand("Select * From T_ExhibitorLocation 
        where F_ExhibitionCode=@Cmbexhibition 
          and F_ExhibitorCode=@exhibitioncode
          and F_Site=@site");
SqlParameter param1  = new SqlParameter();
param1.ParameterName = "@Cmbexhibition";
param1.Value         = Cmb_Exhibition.SelectedValue.ToString();

SqlParameter param2  = new SqlParameter();
param2.ParameterName = "@exhibitioncode";
param2.Value         = Trim(Txt_ExhibitorID.Text);

SqlParameter param3  = new SqlParameter();
para3.ParameterName = "@site";
param3.Value         =cmb_Site.SelectedValue.ToString();

command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);

Then execute it.

Sachu
  • 7,555
  • 7
  • 55
  • 94