.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

multiple textbox search on datagridview in windows application

Posted By: Jayakumar     Posted Date: March 04, 2010    Points:2   Category :Windows Application
hi

i am using windows application.

i need to get search results based on different textbox's

how can it be done at .net 3.5,c#.

Responses
Author: Syed Shakeer Hussain             
Posted Date: March 04, 2010     Points: 5   

Hi JayaKuma ,
First tell your question clearly,
Is your textboxes inside the DataGridview or Outside the DataGridview.

if your textboxes is outside the DataGrid,use the below code:

SqlCommand cmd=new SqlCommand("select * from tablename where first_name like '%"+txtFname.Text+"%' and last_name like '%"+txtLname.Text+"%'",conn);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds,"tablename");
DataGridView1.DataSource=ds.Tables["tablename"];


Author: Jayakumar             
Posted Date: March 04, 2010     Points: 5   

hi

thank for reply..

i am working on windows application(3.5,c#).
i have 4 textbox's.
i have an datagridview.

the result with datagridview shud vary and depends the values typed on the txtboxes

if type value on txtbox1 then i shud get one set of result,
if type value on txtbox2 then i shud get another set of result,

how it can be done...

Author: Syed Shakeer Hussain             
Posted Date: March 04, 2010     Points: 5   

Hi Kumar,

use the below code:

SqlCommand cmd=new SqlCommand("select * from tablename where firstname='"+txtbox1.Text+"' or firstname='"+txtbox2.Text+"' or firstname='"+txtbox3.Text+"' or firstname='"+txtbox4.Text+"'",conn);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds,"tablename");
DataGridView1.DataSource=ds.Tables["tablename"];



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend