Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How can I search the data in a dataset?
 

How can I search the data in a dataset?

I select a database with dataset. And I want to search the column in the dataset. Will it be a fast find instruction instead of compare method.
Thanks for help!
energybody  Friday, April 17, 2009 5:51 AM

Hi energybody,

This base on the table structure and the data in it.
For example.
dataTable1.Select("IDColumn>10 and IDColumn<100");
http://msdn.microsoft.com/en-us/library/det4aw50.aspx

What kind of selection do you want to use?

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byenergybody Monday, April 20, 2009 7:28 AM
  •  
Kira Qian  Monday, April 20, 2009 6:54 AM
DataSet.Select
Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Friday, April 17, 2009 6:32 AM
I get the DataRow[] vRow and how can I get the database's data in dataset.
energybody  Friday, April 17, 2009 9:42 AM
Create a dataadapter and you can use the fill method to retrieve data from database to dataset
Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Friday, April 17, 2009 9:52 AM
I don't understand. I have fill the DataAdapter. but I don't know how to do. Can you write the code for me. Thanks a lots.
energybody  Friday, April 17, 2009 9:54 AM
//Namespace References
using System.Data;
using System.Data.SqlClient

/// <summary>
/// Returns a DataTable, based on the command passed
/// </summary>
/// <param name="cmd">
/// the SqlCommand object we wish to execute
/// </param>
/// <returns>
/// a DataTable populated with the data 
/// specified in the SqlCommand object
/// </returns>
/// <remarks></remarks>
public static DataTable GetDataTable(SqlCommand cmd)
{
    try
    {
        // create a new data adapter based on the specified query.
        SqlDataAdapter da = new SqlDataAdapter();
        //set the SelectCommand of the adapter
        da.SelectCommand = cmd;
        // create a new DataTable
        DataTable dtGet = new DataTable();
        //fill the DataTable
        da.Fill(dtGet);
        //return the DataTable
        return dtGet;
        
    }
    catch (SqlException ex)
    {
        MessageBox.Show(ex.Message);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Please go through this link
http://www.codeproject.com/KB/database/sql_in_csharp.aspx
Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Friday, April 17, 2009 11:04 AM
You use a sql command to select data and return a datatable, it may be slower to search a lot of data that one by one. will it be a faster way.
energybody  Monday, April 20, 2009 2:23 AM

Hi energybody,

From your title, my understand is to get the rows you want in a DataSet. So the DataTable.Select method is very suitable for you. But from your last post, I think you want to retrieve the data from database table. So you should use SqlCommand.
For example.
Sql selection text is: Select * from table1 where id > 10 and id < 100
The SqlCommand should be
SqlConnection sqlConn = new SqlConnection("ConnString");
SqlCommand sqlComm = new SqlCommand("Select * from table1 where id > 10 and id < 100", sqlConn);

Then pass the sqlComm to the GetDataTable method which WiNd0wS-7 has given you.
If you don't put where statement in your sql. It will retrieve all data from table1, that cost time.

If you have any question about it, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, April 20, 2009 6:07 AM
How can I get the column data of rows when I use dataset.select.
energybody  Monday, April 20, 2009 6:46 AM

Hi energybody,

This base on the table structure and the data in it.
For example.
dataTable1.Select("IDColumn>10 and IDColumn<100");
http://msdn.microsoft.com/en-us/library/det4aw50.aspx

What kind of selection do you want to use?

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byenergybody Monday, April 20, 2009 7:28 AM
  •  
Kira Qian  Monday, April 20, 2009 6:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Generate Code for an Event Handler
• Adding a custom property designer to a form that will be inherited
• Why is MyForm derived from Form?
• Intercepting Container Control
• Code Definition Window
• Showing User Control Connection initialize error
• Does it really exist? (System.ComponentModel.Design.ComponentDesigner)
• How to insert combo box in datagrid cell in VB.net 2005?
• getting the events from anoteher class
• Update listbox selected item