943,691 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1002
  • ASP.NET RSS
Jun 19th, 2009
0

Search and Desplay on DataGrid

Expand Post »
Hi all

I have a datagrid filled with data from Oracle database, I have a textbox and a button search and on the textbox a person/user can enter the Title of the book he/she wana search the the results should be displayed in the datagrid

here is the code on btnSearch

ASP.NET Syntax (Toggle Plain Text)
  1. using (OracleConnection conn = new OracleConnection(stringConn))
  2. {
  3. string sql = "select BookID, ISBN, Title, PublishedDate, Edition, Publisher, DepartmentName from Books where Title like '%Title%'";
  4. OracleDataAdapter adap = new OracleDataAdapter(sql, conn);
  5. adap.SelectCommand.Parameters.Add("Title", OracleType.VarChar).Equals(txtSearch.Text);
  6. adap.SelectCommand.Connection.Open();
  7. adap.Fill(dt);
  8. }
  9. DataGrid1.DataSource = dt;
  10. DataGrid1.DataMember = "Books";
  11. DataGrid1.DataBind();
  12. }

but now when I click btnSearch the datagrid which is filled with all the data from the book table just got cleared, instead of desplaying all the books with the title entered in the textbox, please tell me what Im doing wrong

Thanks in advance
Similar Threads
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 19th, 2009
1

Re: Search and Desplay on DataGrid

Some confusion:

1. Do now show the data when user leave textbox empty and click
on button.
For this case, do not execute you code - use if statement to
check the value of textbox.
2. Show a record for the book title entered into textbox.
Do not use like '..%' query. Use where columnname='somethig..'
Last edited by adatapost; Jun 19th, 2009 at 8:33 am. Reason: Spell mistake
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 19th, 2009
0

Re: Search and Desplay on DataGrid

String sql = "Select * From Book Where Title = " + txtSearch.Text
I dont know why I didnt think about that, I guess it is true that inexperience programmers like complicating things

Thanks dude, hope Oracle is gonna love it coz if he does it will goodbye to this line
adap.SelectCommand.Parameters.Add("Title", OracleType.VarChar).Equals(txtSearch.Text);
Last edited by peter_budo; Jun 19th, 2009 at 12:47 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 19th, 2009
0

Re: Search and Desplay on DataGrid

Here is code for your reference.

ASP.NET Syntax (Toggle Plain Text)
  1. string cnstr = "data source=abc;user id=hr;password=hr";
  2.  
  3. // append pattern mach character
  4. textBox1.Text = textBox1.Text + "%";
  5. // Use & - prefix with parametername
  6. string sql = "select * from employees where first_name like
  7. &test";
  8. // No need to set reference of connecton object.
  9. OracleDataAdapter adp = new OracleDataAdapter(sql,
  10. cnstr);
  11. adp.SelectCommand.Parameters.Add("&test",
  12. OracleType.VarChar );
  13. adp.SelectCommand.Parameters[0].Value = textBox1.Text;
  14.  
  15. DataTable dt = new DataTable();
  16. // Fill method automatically opens & close the connection
  17. adp.Fill(dt);
  18. DataGrid1.DataSource = dt;
  19. DataGrid1.DataBind();
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 23rd, 2009
0

Re: Search and Desplay on textbox or label

i have a problem on searching data from table and displaying it into the textbox or label...pls help me on this problem tnx..
Reputation Points: 10
Solved Threads: 1
Newbie Poster
obicerno is offline Offline
7 posts
since Sep 2009

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: What's N-Tier .. !! Need Tutorials
Next Thread in ASP.NET Forum Timeline: Interface Dynamism





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


Follow us on Twitter


© 2011 DaniWeb® LLC