473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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??

Expand|Select|Wrap|Line Numbers
  1. string myTextBox;
  2. myTextBox = myDataSet.myTableAdapter;
  3.  
  4. textBox1.Text = myTextBox;
Jun 1 '07 #1
1 1238
nateraaaa
663 Expert 512MB
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.

Expand|Select|Wrap|Line Numbers
  1. DataSet ds = new DataSet();
  2.  
  3. //create connection object
  4. SqlConnection oConn = new SqlConnection(put your connection string to the database here);
  5. //using System.Data.SqlClient;
  6. try
  7. {
  8. //Make a db connection
  9. oConn.Open();
  10. //retrieve data
  11. //Create a command object to execute the stored procedure
  12. SqlCommand oCmd = new SqlCommand();
  13. oCmd.Connection = oConn;
  14. oCmd.CommandType = CommandType.StoredProcedure;
  15. oCmd.CommandText = "enter the name of your stored procedure here";
  16. ds.Clear();
  17.  
  18. SqlDataAdapter oDataAdapter = new SqlDataAdapter();
  19. oDataAdapter = new SqlDataAdapter(oCmd.CommandText, oConn.ConnectionString);
  20. oDataAdapter.SelectCommand = oCmd;
  21. oDataAdapter.Fill(ds);
  22.  
  23. for(int i = 0; i < ds.Tables[0].Rows.Count; i ++)
  24. {
  25. if(TextBox1.Text == ds.Tables[0].Rows[i]["column name"].ToString())
  26. {
  27. //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.  
  28. //Tell the user the value already exists. Or do whatever you want if the Text Box value and column value are equal
  29. }
  30. else
  31. {
  32. //do something else
  33. }
  34. }
This shoudl get you on the right track.

Nathan
Jun 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Lee | last post by:
Hi, When I use DataSet.WriteXml(filename, XmlWriteMode.DiffGram), the xml file contains current values (at <InvDataSet> node) and original value (at <diffgr:before> node) - this means the...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
2
by: SMG | last post by:
Hi there, We have a DataSet with one datatable with three columns and multiple rows. 1st Column : Unique Key 2nd Column : Value to Change 3rd Column : Value to Change Based on some...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
1
by: Joey Lee | last post by:
Hi, I am confused as what the DataSet Merge() function does. Currently I have two datatable which was selected from different table in mssql. Now with both different datatable. there are...
4
by: Rob | last post by:
Hi, I've been going at this for a few days and can't see the problem. Does anyone see a problem with this code? I have a call to a function that returns a dataset and when I assign values to...
1
by: Matt Tinson | last post by:
Hello I have a datagrid with a datetimepicker column in it, which is bound to a dataset (MyDataset). The column in the dataset set that is mapped to the datetimepicker is called MyOrderDate and...
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns...
5
by: needin4mation | last post by:
Hi, I have a webservice that just returns a count: public DataSet HelloWorld() { OdbcConnection conn = new OdbcConnection("DSN=xxx"); String sqlString = "select count(*) as employee from...
0
by: BVA3105 | last post by:
i update a database with a dataset and a SqlAdapter with success but when i clear and refill my dataset i always retreive the old values. I have to wait for 5 seconds to get the corrects values. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.