I know this question has been asked many of times about how to create a search button. I am very new to C# programming and I am having a hard time creating a search and just haven't found what I am looking for from other posts. So I hope someone can help me.
I have created a Windows Form Application in Visual Studio Express C# and I have a form setup using "Details" view from my DataSet and the data shows up correctly in the application when I scroll from record to record. My data is stored in a sdf file. I want to have to have people either enter in an "account number" or a persons "last name" and then be able to hit the search button. And after the search button the prearranged fields would update with the information. If it is easier to do I can have the Account number and last Name in a drop down box and then a text box next to it. Any assitance is greatly appreciated for a newbie. I have included a copy of my code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void custtableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.custtableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.custDataSet);

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void custtableBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
        {
            this.Validate();
            this.custtableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.custDataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'custDataSet.custtable' table. You can move, or remove it, as needed.
            this.custtableTableAdapter.Fill(this.custDataSet.custtable);

        }

        private void file_Name_12TextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.custtableTableAdapter.FillBy(this.custDataSet.custtable);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void btnfind_Click(object sender, EventArgs e)
        {

        }
    }
}

Well in terms of handling the account number and surname search possibilities, you can use a TryParse to distinguish which you are dealing with, I am assuming an account number is entirely numeric.

string InputFromTextBox = "0011223344";
int OutputAccountNumber;

// if bool = true, its account number, else false, surname
bool IsAccountNumber = int32.TryParse(InputFromTextBox, out OutputAccountNumber);

Edited 4 Years Ago by Mike Askew

This question has already been answered. Start a new discussion instead.