this is my code trying to compare the strings in the text box2 and display the matched string in the label i am getting an error please help me
protected void Button1_Click(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert comparative values('" + TextBox1.Text + "','" + TextBox2.Text + "')", con);
cmd.ExecuteNonQuery();
SqlDataReader reader = null;
// cmd.Parameters.AddWithValue("@name", TextBox2.Text);
//cmd.Parameters.AddWithValue("SELECT FROM places where name=@name",TextBox2.Text);
cmd.Parameters.AddWithValue("select textbox2.text from places where [email protected]",con);
reader = cmd.ExecuteReader();
while (reader.Read())
{
TextBox2.Visible = true;
TextBox2.Text = Convert.ToString(reader["TextBox2"]);
}
Label4.Text= TextBox2.Text;
con.Close();
}

Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 18, 2015, 3:20 AM EDT
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection connect = new SqlConnection("Data Source=sqlserver;Initial Catalog=dbname;Integrated Security=true;");
connect.Open();
SqlCommand scom = new SqlCommand();
scom.Connection = connect;
scom.CommandText = "Select * from tablename where columname = @Name";
scom.Parameters.AddWithValue("@Name", TextBox1.Text.ToString());
SqlDataReader sdr = scom.ExecuteReader();
if (sdr.Read())
{
Label1.Text = "Found" + TextBox1.Text;
}
else
{
Label1.Text = "Not Found";
}
connect.Close();
}
----------------------------------------------------------------------------------
If this answer helps you. Please validate as "Accept answer".
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 18, 2015, 12:26 AM EDT
inser query like
insert into table(column1,column2) values('value1','value2')
and select like
select columnname from table
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 18, 2015, 1:58 AM EDT
are you trying to compare textbox2 value with db value?
Krishna39 reputationPosted Mar 18, 2015, 2:35 AM EDT
Krishna39 reputationPosted Mar 23, 2015, 2:33 AM EDT
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 23, 2015, 3:40 AM EDT
and pass the value like this