Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Button 1

Status
Not open for further replies.

MJV57

Programmer
Apr 18, 2009
87
CA
I have a form with approx 100 fields from a data table. And I have been struggling with adding a search button that would allow me to pull up a record based on a particular field in that record. Can anyone lead me in the right direction on this.
Thank You
 
When I put the following code in


private void findBN_Click(object sender, EventArgs e)
{
dataView.RowFilter = "estimateno = estfindTB.Text";
}




the name dataView does not exist in the current context.
 
I have snippet in VB that do rowfilter is like this
Code:
   Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        Dim aFilter As String = ""

        '//Search name starts with
        aFilter = "LastName Like '" & txtSearch.Text & "*'"

        ' //To Search name contains..
        ' //Uncomment the next line
        'aFilter = "LastName Like '" & "*" & txtSearch.Text & "*'"


        '//Create the filter string.

        If txtSearch.Text.Trim = "" Then
            aFilter = ""
        Else
            aFilter = aFilter
        End If

        '//Apply the filter.
        ds_Northwind.Tables("Employees").DefaultView.RowFilter = aFilter

    End Sub
can be converted to
Code:
   private void txtSearch_TextChanged(object sender, System.EventArgs e)
   {
		string aFilter = "";

		////Search name starts with
		aFilter = "LastName Like '" + txtSearch.Text + "*'";

		// //To Search name contains..
		// //Uncomment the next line
		//aFilter = "LastName Like '" & "*" & txtSearch.Text & "*'"


		////Create the filter string.

		if (txtSearch.Text.Trim() == "")
		{
			aFilter = "";
		}
		else
		{
			aFilter = aFilter;
		}

		////Apply the filter.
		ds_Northwind.Tables["Employees"].DefaultView.RowFilter = aFilter;

	}
converted by a tool

this does a good job

Zameer Abdulla
 
Thanks Zameer for staying with me but how would this change if the search item is an integer.
 
Should be something like
Code:
aFilter = "Id=" + txtSearch.Text;
or may be you can convert the text to integer an pass to the filter for more clarity.


Zameer Abdulla
 
Im still having problems I get the following errors:

The best overloaded method match for 'EstimatorC.EstimatorDataSet.QuoteCalcHeaderDataTable.this[int]' has some invalid arguments E:\VisualStudioProjects\EstimatorC\EstimatorC\Estimate.cs 1653 13 EstimatorC

Argument '1': cannot convert from 'string' to 'int' E:\VisualStudioProjects\EstimatorC\EstimatorC\Estimate.cs 1653 46 EstimatorC


My Code is as follows:

private void findBN_Click(object sender, EventArgs e)
{
string aFilter = "";

////Search name starts with

aFilter = "Id=" + estfindTB.Text;

////Create the filter string.

if (estfindTB.Text.Trim() == "")
{
aFilter = "";
}
else
{
aFilter = aFilter;
}

////Apply the filter.
estimatorDataSet.QuoteCalcHeader["estimateno"].DefaultView.RowFilter = aFilter;

}
 
As I said try converting the string into integer and the field name
Code:
aFilter = "estimateno=" + System.Convert.ToInt32(estfindTB.Text);



Zameer Abdulla
 
Thanks, but please hang in with me. Still get the same errors after changing the code to this.



private void findBN_Click(object sender, EventArgs e)
{

string aFilter = "";

////Search name starts with

aFilter = "estimateno=" + System.Convert.ToInt32(estfindTB.Text);

////Create the filter string.

if (estfindTB.Text.Trim() == "")
{
aFilter = "";
}
else
{
aFilter = aFilter;
}

////Apply the filter.
estimatorDataSet.QuoteCalcHeader["estimateno"].DefaultView.RowFilter = aFilter;


}
 
see the differnce between mine and yours
Code:
ds_Northwind.Tables["Employees"].DefaultView.RowFilter = aFilter;

Code:
estimatorDataSet.QuoteCalcHeader["estimateno"].DefaultView.RowFilter = aFilter;

It should be like
Code:
Dataset_Name.Tables["Table_Name"].DefaultView.RowFilter = aFilter;


Zameer Abdulla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top