Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CSharp - Best collection type to use for updating

Posted on 2011-09-20
4
Medium Priority
?
156 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 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