| | |
Search and Desplay on DataGrid
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
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
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
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)
using (OracleConnection conn = new OracleConnection(stringConn)) { string sql = "select BookID, ISBN, Title, PublishedDate, Edition, Publisher, DepartmentName from Books where Title like '%Title%'"; OracleDataAdapter adap = new OracleDataAdapter(sql, conn); adap.SelectCommand.Parameters.Add("Title", OracleType.VarChar).Equals(txtSearch.Text); adap.SelectCommand.Connection.Open(); adap.Fill(dt); } DataGrid1.DataSource = dt; DataGrid1.DataMember = "Books"; DataGrid1.DataBind(); }
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
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
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..'
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
Failure is not fatal, but failure to change might be. - John Wooden
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.
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Here is code for your reference.
ASP.NET Syntax (Toggle Plain Text)
string cnstr = "data source=abc;user id=hr;password=hr"; // append pattern mach character textBox1.Text = textBox1.Text + "%"; // Use & - prefix with parametername string sql = "select * from employees where first_name like &test"; // No need to set reference of connecton object. OracleDataAdapter adp = new OracleDataAdapter(sql, cnstr); adp.SelectCommand.Parameters.Add("&test", OracleType.VarChar ); adp.SelectCommand.Parameters[0].Value = textBox1.Text; DataTable dt = new DataTable(); // Fill method automatically opens & close the connection adp.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind();
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- how to use data grid in vb.net using odbc connection (VB.NET)
- Data grid urgent help....very urgent (VB.NET)
- Urgent Help !PLz help.....plzz (VB.NET)
- connect datagrid to access db using ado code in vb6 (Visual Basic 4 / 5 / 6)
- how to trap the values of a particular row in datagridview (C#)
- Search in Datagrid... (VB.NET)
- To Search a record in datagridview (VB.NET)
- search in datagrid (C#)
- Datagrid Search and Replace (Visual Basic 4 / 5 / 6)
Other Threads in the ASP.NET Forum
- Previous Thread: What's N-Tier .. !! Need Tutorials
- Next Thread: Interface Dynamism
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net beginner bottomasp.net box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects opera order problem ratings redirect registration relationaldatabases reportemail rotatepage search security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql ssl tracking treeview validatedate validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment wizard xml xsl






