Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PIVOT table in DataSet to Insert into DB

Posted on 2013-01-13
7
Medium Priority
?
379 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

721 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