Solved

CSharp - Best collection type to use for updating

Posted on 2011-09-20
4
147 Views
Last Modified: 2012-06-27
Hi

I need some advice on the best way to achieve something

I need to do a SQL Query, that will return some information: Item, Company, Stock

I then need to run another SQL Query, that will have some more information, Demand, Availability. I then want this to be updated, alongside the first lot of information

I don't really want to create a temporary table or do anything within the database, I am trying to find an "offline" way of handling it - but what is the best way of doing that ?

Once that is done, I then want to be able to cycle through it, and if one value is greater than another, for an action to take place

I hope that this makes sense

Thanks
0
Comment
Question by:seancurt
  • 2
4 Comments
 
LVL 18

Expert Comment

by:lludden
ID: 36567122
Dot Net DataTables and Datasets are specifically made for this type of application.
0
 

Author Comment

by:seancurt
ID: 36567196
I did try a DataTable, and everything went in ok. Then trying to do the update, I believe the filter needs to be done on the DataSet, but it seems that the DataTable's dataset is null. Is this beacause I am doing dt.rows.add(row), rather than creating a dataset then putting it into the table - if that makes any sense???


DataSet ds = dt.DataSet;
DataRow[] row = ds.Tables["DataSet"].Select("Item = 'ABC' AND Company = 'DEF'");
0
 
LVL 18

Accepted Solution

by:
lludden earned 500 total points
ID: 36567675
This might be a good time to use a strongly typed dataset.

Create the dataset and fill it.
Make modifications to it.
Call the Update method on the tableadapter to persist your changes.  You need to have the rows be part of a dataset.

0
 
LVL 9

Expert Comment

by:rinfo
ID: 36573717
I think you are confusing about dataset and datatable.
Dataset are  in -memory copy of  a database.
And datatable are table that constitute the database / dataset.
A dataset obiviously could have a number of table/datatable.
For your job you need to define 2 datatable for the dataset. - one for each query.
And these datatable would be populated as follows.
SqlConnection mySqlConnection =new SqlConnection(Your connection string);
 SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
 SqlCommand.CommandText =your query to fetch data from table1";
 SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
SqlDataAdapter.SelectCommand = mySqlCommand;
 DataSet myDataSet = new DataSet();
 mySqlConnection.Open();
  int numberOfRows = mySqlDataAdapter.Fill(myDataSet, "stocklist");//denote any name for emplouee
    Console.WriteLine("numberOfRows = " + numberOfRows);
    SqlDataAdapter.SelectCommand.CommandText =
     yourquery to fetch data from second query.
    numberOfRows = mySqlDataAdapter.Fill(myDataSet, "BOStocklist");//
    Console.WriteLine("numberOfRows = " + numberOfRows);  SqlConnection.Close();

    foreach (DataTable myDataTable in myDataSet.Tables) {
      Console.WriteLine("\nReading from the " +
        myDataTable.TableName + "DataTable");
      foreach (DataRow myDataRow in myDataTable.Rows)
      {
        foreach (DataColumn myDataColumn in myDataTable.Columns)
        {
          Console.WriteLine(myDataColumn + "= " +
            myDataRow[myDataColumn]);
        }
      }
    }
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now