this is my program
public partial class message : System.Web.UI.Page
{
string constring = ConfigurationManager.ConnectionStrings["AnonymiousSocialNetworkConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
txtuseremil.Text = Session["emid"].ToString();
}
protected void btnsend_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = new SqlConnection(constring);
string value = txtmsg.Text;
if (value.Contains(SqlCommand cmd = new SqlCommand("select keyword from messageanalysis where keyword=@value"))// <--MY PROBLEM
{
con.Open();
lblStatus.Text = "Normal"; <-- I WANT TO DERIVE THIS VALUE FROM TABLE ACCORDING TO THE VALUE I GET FROM keyword
Frdsclass.Text = "Just Friend"; <--- I WANT TO DERIVE THIS VALUE FROM TABLE ACCORDING TO THE VALUE I GET FROM keyword
SqlCommand cmd = new SqlCommand("insert into messagetable(sendid,message,userid,emotional,friendsclassify) values (@snd,@msg,@usr,@emo,@frdcl)", con);
cmd.Parameters.AddWithValue("@snd", txtsndmail.Text);
cmd.Parameters.AddWithValue("@msg", txtmsg.Text);
cmd.Parameters.AddWithValue("@usr", txtuseremil.Text);
cmd.Parameters.AddWithValue("@emo", lblStatus.Text);
cmd.Parameters.AddWithValue("@frdcl", Frdsclass.Text);
cmd.ExecuteNonQuery();
con.Close();
}
how can i search a word or sentence in database table?? is my method correct?? plz help if u have a solution
Best Answer
your question is not quite clear. If you want to search a substring in a varchar field you can do it with a like
SELECT * FROM yourtable WHERE yourvarcharfield LIKE '%yoursearchstring%'
if you wanto look in different fields you can chain with ...or yourotherFild like '%yousearchstring%'
if you want to search those records that start with your searchstring the condition is
..like 'yoursearchstring%'