Krishna

Krishna

  • NA
  • 37
  • 9.3k

comparing multiple strings with the database

Mar 23 2015 7:27 AM
i had a text box in which i am passing two  string separated by (& )
example :hyderabad & goa
i want the strings to be compared with the database and display the result which is available in the database
 i had a code 

 protected void Button1_Click(object sender, EventArgs e)
    {

        SqlCommand cmd = new SqlCommand("insert  comparative values('" + TextBox1.Text + "','" + TextBox2.Text + "')", con);
        cmd.ExecuteNonQuery();
        SqlCommand scom = new SqlCommand();
        scom.Connection = con;
        scom.CommandText = "Select * from places where names= @Name";
        scom.Parameters.AddWithValue("@Name", TextBox2.Text.ToString());
        string[] myArray = TextBox2.Text.Split(new Char[] { '&' });
        SqlDataReader sdr = scom.ExecuteReader();
        if (sdr.Read())
        {
            Label4.Text =  TextBox2.Text;
        }
        else
        {
            Label4.Text = "Not Found";
        }
        con.Close();
           
     }
          thanks in advance

Answers (11)