943,733 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 624
  • ASP.NET RSS
Nov 27th, 2008
0

error on search code

Expand Post »
hai friends i am writing the code for search button;

while i am wrote and complied that it gives the following error.
so many times i checked and posting into the forum now please clarify this problem..


code is:

asp.net Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12.  
  13. public partial class nextpage : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. SqlConnection con = new SqlConnection("user id=sa;password=vikram;database=MUDIAM_INC");
  18. SqlCommand cmd = new SqlCommand("select * from mudiamINC", con);
  19. cmd.Connection = con;
  20. con.Open();
  21. }
  22. protected void Button1_Click(object sender, EventArgs e)
  23. {
  24. SqlConnection con = new SqlConnection("user id=sa;password=vikram;database=MUDIAM_INC");
  25. SqlDataAdapter da = new SqlDataAdapter("select * from mudiamINC where fname like" + TextBox1.Text + " %", con);
  26. DataSet ds = new DataSet();
  27. da.Fill(ds, "mudiamINC");
  28. con.Open();
  29. SqlCommand cmd = new SqlCommand();
  30. cmd.Connection = con;
  31. cmd.CommandText = "select * from mudiamINC";
  32.  
  33. }
  34. }

Error Is:

ASP.NET Syntax (Toggle Plain Text)
  1. An expression of non-boolean type specified in a context where a condition is expected, near 'likekrani'


please check the error and tell me the correct solution for that..
ASAP


another one is search information could be displayed in the browser in a tabular format.
please clarify my doubt.

please...please...please...please...please...please...please...please...
Last edited by peter_budo; Nov 28th, 2008 at 1:28 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 27th, 2008
0

Re: error on search code

I think the problem is where you're building your select
ASP.NET Syntax (Toggle Plain Text)
  1. SqlDataAdapter da = new SqlDataAdapter("select * from mudiamINC where fname like" + TextBox1.Text + " %", con);
I'm think you need a space after the like, but not before the %
ASP.NET Syntax (Toggle Plain Text)
  1. SqlDataAdapter da = new SqlDataAdapter("select * from mudiamINC where fname like " + TextBox1.Text + "%", con);

Note however that I suspect this code is 'bad form'. You are taking user input without validation and putting it into SQL queries. This potentially puts your application at risk for SQL injection attacks.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Nov 28th, 2008
0

Re: error on search code

please send me the correct code for that...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 28th, 2008
0

Re: error on search code

I think for testing your example, you could ignore the 'bad form'.

But if this will be accessed by other people (especially the public) that might ever have malicious intent then you should address this and any other code that might be subject to attack.

For more information on protecting yourself from SQL Injection attacks, I recommend the following article:

http://msdn.microsoft.com/en-us/library/ms998271.aspx
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: I'm new and need help and advice!
Next Thread in ASP.NET Forum Timeline: creating pdf files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC