Solved

SQL Temp tables and/or arrays VS 2008 C#

Posted on 2010-11-11
3
421 Views
Last Modified: 2013-12-17
I have to write a snippet of code that will interface with an accounting program. In that program the data will be in a datagrid that I can read but not write. Using VS 2008 C# and MS SQL Server 2005 I have two questions:
1) I can extract the data from the grid and then write into a SQL temp table. Now given that multiple users can run this program at the same time, how do I insure the SQL temp table that is created is unique?
2) Instead of using a SQL temp table, is there any kind of variable array method I can use to temporarily hold the values, display them on the screen in a datagridview and then add any additional functionality?

I am trying to determine if using SQL temp table is my only choice or is there a more efficient way of handling this situation?
0
Comment
Question by:rwheeler23
[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
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34115421
For the first part, if you create the tables as #tablename, these are session specific and as long as you use a specific connection string that is unique per user (such as including user name in connection string as part of "application name") - it will be unique to the user (session).
The other option is to have a normal table that you put data temporarily into.  You can add a key to the table (a GUID generated at app startup) that uniquely identifies which session owns those subset of records.

Now, while the above will work using SQL as a backend, if you only have very little data, you could just store it in an ArrayList or something compatible for display on a DataGrid.  It is able to bind to collections easily.  For example see here

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=81
0
 

Author Comment

by:rwheeler23
ID: 34116028
Please excuse my ignorance as I am still learning VS. As you can see below I have created the loop that will go through the datagrid of the accounting program. Now I need to extract certain values out of that grid and get it into the type of grid to which you refer. I have tried following the example you list but I not getting it right. What is the correct syntax to populate a datagrid that I can then display?

I have put two sample fields in the example:
DocAmount
DocNumber
try
            {
                /* Loop through the apply documents buffer and insert records into datalist */
                TableError err;
                decimal DocAmount;
                string DocNumber;
                

                /* Create a reference to the Apply Documents grid */
                PmApplyToOpenOpenTable PmApplyToOpenOpenTable;
                
                /* This points to the form table buffer */
                PmApplyToOpenOpenTable = Dynamics.Forms.PmApplyToMaintenance.Tables.PmApplyToOpenOpen;
                
                /* Read through the table buffer extracting a record for each open payables document */
                err = PmApplyToOpenOpenTable.GetFirst();

                while (err != TableError.EndOfTable)
                {
                    DocAmount = PmApplyToOpenOpenTable.AppliedAmount;
                    DocNumber = PmApplyToOpenOpenTable.ApplyToDocumentNumber;

                }
            }
            catch (Exception ex)
            {
                string eMsg = "002: ERROR:" + ex.Message;
                if (stackTraceWanted) eMsg += "\n" + ex.StackTrace;
                MessageBox.Show(eMsg);
            }
        }

Open in new window

0
 

Author Comment

by:rwheeler23
ID: 34116328
By the way, I am used to using a DataGridView so what I a looking to do is to find out how to populate a data grid view with the values in this datagrid coming from the accounting program.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

763 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