Skip to content

C# intellisense search bar for use with datagrid

jed ong

Asked Jul 11, 2008, 7:57 PM EDT1 answer
Share
LinkedInX
hi! i'm a new programmer and i was wondering.. how can you search using a textbox and the output comes out on the datagrid for example: I typed the letter "A" and all the names of a certain column, which starts with letter "A" is shown.. then i typed "B"  so the textbox contains "AB"  then all the names that starts with "AB" are shown in the datagrid.

can you help me? thanks :)

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    If you're  using  a  data  base  you  can  define a stored procedure and use the sql keyword like, if you use sql server for example

    CREATE PROCEDURE Search  @letter Char
    AS
    Select  [something here] from [something here] where [your targeted field] like @letter
    GO
    Then create a connection to your data base
    create a command

    sqlCommand oCommand = new sqlCommand("Search");//Remarque that we use the name of the stored procedure
    oCommand .CommandType = CommandType.StoredProcedure;

    //Now create an sql param
    sqlParameter myParam = new sqmParameter("@letter", sqlDBtype.Char);
    myParam.Value = textbox.text;
    oCommand.Parameters.add(myParam);
    //now create a data set to stock data wirth
    DataSet ds = new DataSet();
    //An sqldataadapter to fill the dataset
    sqlDataAdapter oAdapter = new sqlDataAdapter(oCommand);
    //Fill the data into data set
    oAdapter.Fill(ds);
    //Now tie your control to the dataset

    dataGridview.dataset = ds;
    dataGrifView.datamember = ds.Tables[0].TableName

    try it
    0