Solved

PIVOT table in DataSet to Insert into DB

Posted on 2013-01-13
7
371 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
[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
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

734 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