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 BabuPosted Mar 18, 2015, 7:20 AM
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".
Keertti Raj Thangavelu BabuPosted Mar 23, 2015, 7:40 AM
and pass the value like this
KrishnaPosted Mar 23, 2015, 6:33 AM
KrishnaPosted Mar 18, 2015, 6:35 AM
Keertti Raj Thangavelu BabuPosted Mar 18, 2015, 5:58 AM
are you trying to compare textbox2 value with db value?
Khargesh RajputPosted Mar 18, 2015, 4:26 AM
inser query like
insert into table(column1,column2) values('value1','value2')
and select like
select columnname from table