?
Solved

CSharp - Best collection type to use for updating

Posted on 2011-09-20
4
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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