Solved

PIVOT table in DataSet to Insert into DB

Posted on 2013-01-13
7
359 Views
Last Modified: 2013-02-12
Hi All, I really need some help with this issue:
I have a stored procedure creating a PIVOT table in MSSQL. I need to Insert the table (PIVOT result) into another DataBase.
I use C# EnterpriseLibrary.Data Objects to connect to DB.
I tried to make an insert SQL statement using the data in my dataset tabel object but it doesnt work. this is my code:
                String sqlCommand = "EXPORT_TOAS400_SCHEDULAR_FINAL";
                DbCommand dbCommand = Data.dbS.GetStoredProcCommand(sqlCommand);
                Data.dbS.AddInParameter(dbCommand, "opr_file_num", DbType.Int32, CurrFileNum);

                Data.dbS.LoadDataSet(dbCommand, ds, "SCHED_AS400");

                    sqlCommand = "INSERT INTO  [DB2SRV].[S6577E6F].[BPCSELTFT].[SF#272FA] "
               + " (SASORD,SAPROD,SACOPN,SAQTYB,SACORD,SACLIN,SARDTE,SACRIT,SA240,SA250"
               + " ,SA261,SA300,SA370,SA380,SA496,SA505,SA550,SA575,SA577,SA580,SA660"
               + " ,SA670,SASDDT,SANOD,SACLAS,SAPRMS,SACAT4,SAF240,SAF670,SAORDT,SANOCL)"
               + "  SELECT SORD,XL_ELTEKPN,XL_CURRENTOPERATION,XL_QTY,XL_CUSTOMERORDER,XL_ORDERLINE, EXP2,XL_CRITICALVALUE,240,"
               + " 250,261,300,370,380,496,505,550,575,577,580,660,670,EXP3,XL_DELAYEDDAYS,XL_ITEMCLASS,EXPR1,XL_HSTYPE,EXPR4,XL_CURRENTEND, XL_ORDERTYPE,XL_NUMLAYERS"
                    +" FROM " + ds.Tables["SCHED_AS400"];

             Data.dbS.ExecuteNonQuery(Data.dbS.GetSqlStringCommand(sqlCommand
0
Comment
Question by:Hagita
  • 4
  • 2
7 Comments
 

Author Comment

by:Hagita
ID: 38777274
Thank you Mark. I will rephrase my question so its clearer:
How can I update MSSQL db with data from a dataset table object without looping through table rows. I am using  C# EnterpriseLibrary.Data Objects to connect to DB.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38778361
What is not clear is what "doesnt work" with the code you posted, in other words, is there:
1. An error message, if so what is it.
2. The wrong data gets added, if so what is it and what were you expecting,
3. Something else.

Also, where is the "PIVOT table"?
0
 

Author Comment

by:Hagita
ID: 38781622
I get "Invalid object name 'SCHED_AS400'."

it seems like the provider is looking for a Data Base table. I want to transfer my Dataset table object
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38782450
It sounds like the table SCHED_AS400 does not exist in your current database (the one declared in your connection string).
0
 

Accepted Solution

by:
Hagita earned 0 total points
ID: 38863858
Decided to loop through rows and update only changed values. (saved original values in another dataset and compared each field value.)
0
 

Author Closing Comment

by:Hagita
ID: 38879438
Couldnt find a better solution
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Image(2) 3 28
Round up to 100% in .NET 10 45
MVC5 Dataformat String for Phone not working 3 9
SQL Split character from numbers 3 18
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

760 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

18 Experts available now in Live!

Get 1:1 Help Now