Dataset Values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • obrienkev
    New Member
    • May 2007
    • 63

    #1

    Dataset Values

    Hi all,

    How do I use the values of the dataset? I want to compare those values with a textBox.

    I have the table adapter set up to run a Select query on the dataset.

    Is it something like this??

    Code:
    string myTextBox;
    myTextBox = myDataSet.myTableAdapter;
    
    textBox1.Text = myTextBox;
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    The dataset should be loaded with data from a database table or some type of list. Then you would loop through your dataset to compare the textbox value to the column values in the dataset.

    Try something like this.

    Code:
    DataSet ds = new DataSet();
    
    //create connection object
    SqlConnection oConn = new SqlConnection(put your connection string to the database here);
    //using System.Data.SqlClient;
    try
    {
    //Make a db connection
    oConn.Open();
    //retrieve data
    //Create a command object to execute the stored procedure
    SqlCommand oCmd = new SqlCommand();
    oCmd.Connection = oConn;
    oCmd.CommandType = CommandType.StoredProcedure;
    oCmd.CommandText = "enter the name of your stored procedure here";
    ds.Clear();
    
    SqlDataAdapter oDataAdapter = new SqlDataAdapter();
    oDataAdapter = new SqlDataAdapter(oCmd.CommandText, oConn.ConnectionString);
    oDataAdapter.SelectCommand = oCmd;
    oDataAdapter.Fill(ds);
    
    for(int i = 0; i < ds.Tables[0].Rows.Count; i ++)
    {
    if(TextBox1.Text == ds.Tables[0].Rows[i]["column name"].ToString())
    {
    //column name is the name of the column in your database table that you are checking to see if the TextBox value is equal to.  
    //Tell the user the value already exists. Or do whatever you want if the Text Box value and column value are equal
    }
    else
    {
    //do something else
    }
    }
    This shoudl get you on the right track.

    Nathan

    Comment

    Working...