Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PIVOT table in DataSet to Insert into DB

Posted on 2013-01-13
7
Medium Priority
?
384 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

971 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