2 Replies - 33999 Views - Last Post: 06 March 2010 - 09:18 AM Rate Topic: -----

#8 mohdabid  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 13
  • Joined: 25-October 07

Re: Search database using textbox control values in c# .net windows applic

Posted 14 January 2009 - 01:54 PM

Hi,

I am working on c# .net windows application.

In a window form i have one textbox control, and a button.
when i click the button i want to search the database using the textbox value.

how to accomplish this. please help ...

thanks.
Was This Post Helpful? 1

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Search database using textbox control values in c# .net windows applic

Posted 14 January 2009 - 02:24 PM

First and foremost, you're going to have to show us what you've tried so far to accomplish this, to help with this here is a tutorial to help with the basics of working with SQL Server with C#.

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Tomi*


Reputation:

Re: Search database using textbox control values in c# .net windows applic

Posted 06 March 2010 - 09:18 AM

View Postmohdabid, on 14 January 2009 - 12:54 PM, said:

Hi,

I am working on c# .net windows application.

In a window form i have one textbox control, and a button.
when i click the button i want to search the database using the textbox value.

how to accomplish this. please help ...

thanks.


I wanted to figured this too. After failing Google-ing a clear way I build a method, a simple one.

/* variables explanation
The DataSet is > visitDataSet < change it to your own.
j > number of columns < change it to your own.
textBox1.Text > the text you're looking for < change it to your own.
label2 > represent the answer < change it to your own.
*/
int count=visitDataSet.Visits.Count;//saves how many rows in table
string find=null;
for (int i=0;i<=count-1;i++)
{
for(int j=0;j<=7;j++)
{
if (visitDataSet.Visits.Rows[i].ItemArray[j].ToString().Equals(textBox1.Text))
{ find += visitDataSet.Visits.Rows[i].ItemArray[j].ToString()+"\n";}

}

}
if (find == null)
label2.Text = "No records found";
else
label2.Text = find; 

Was This Post Helpful? 0

Page 1 of 1