Searching in datatable

csharp , db Malawi
  • 9 years ago

    Hi all,

    I want to search a particular row from a datatable and display it on datagrid. Am using sql queries to do search operation. The statements i have written in code is like this(am using a cldb dll here)

    private void Search_Click(object sender, System.EventArgs e)

    {

    ds = clDb.oDb.executeDataSet("Mydatabase","SELECT * FROM Books WHERE '"+listBox1.SelectedItem.ToString()+"' = '"+searchtxtbx.Text+"'");

    dataGrid1.DataSource = ds;

    dataGrid1.DataMember = ds.Tables[0].ToString();

    }

    When i click on search button it is showing empty screen on datagrid. Can anyone pls tel me where i have done the mistake..

  • 9 years ago

    Hi Priya,

    Acually you have done one mistake in the String concatenation concept

    You just remove the single quote start and end point of the  listbox1.SelectedItem.ToString().

    ds = clDb.oDb.executeDataSet("Mydatabase","SELECT * FROM Books WHERE  Remove['] "+listBox1.SelectedItem.ToString()+" Remove['] = '"+searchtxtbx.Text+"'");

     Now you try after remove this single quotes.

     Good Luck

    Regards

    Hari K......

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe