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
Solved

PIVOT table in DataSet to Insert into DB

Posted on 2013-01-13
7
366 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

856 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