sudipchand7139 sudipchand7139 - 6 months ago 13
SQL Question

Sql Query For Search Not Working

Here I am trying to check the whether the word is present in table

or not.Here I am giving an input through
to check the presence of word in table. And on linkbutton i.e
click and if the input word is present in table the label i.e
text should be "found" if word is not present in table label text should be "not found".

Now the problem is that even if I enter the word that is present in table
text is "not found" the word .Below is what i have done.

Html used

<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="txtentrytitle" CssClass="textbox2" placeholder="Entry Title..." Width="100%" runat="server" Height="104px"></asp:TextBox>
<CKEditor:CKEditorControl ID="CKEditorControl2" BasePath="~/ckkeditor" runat="server" AutoPostBack="True">
<asp:LinkButton ID="lblviewentry" CssClass="btn btn-primary shadow1" runat="server" OnClick="lblviewentry_Click"> <span aria-hidden="true" class="glyphicon glyphicon-option-vertical"></span></asp:LinkButton>

Code behind linkbutton

DataTable dt = OJC.GetBadWord(CKEditorControl2.Text);
if (dt.Rows.Count>0)
Label2.Text="Not Found"

Method Used

public DataTable GetBadWord(string Word)
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myconnection"].ConnectionString);
string sql = "select *from tblword where Word=@Word";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@Word", Word);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
return dt;



Let me clear one point that in your sql query you are comparing word with CKEditor's Text

select *from tblword where Word=@Word

Here @Word is whole text of CKEditor i.e it may be single word or multiple lines right. In that situation your sql will not work as expected. Instead I will suggest you to search your column value in given CKEditor Text i.e

select *from tblword where @Word like '%'+Word+'%'

Here @Word can be multiple line you should have set proper length for it.