473,672 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# SqlDataAdapter to ODBC export

1 New Member
Hi all,

I am trying to adapt a program, by transforming the output part of it, so it can export to ODBC(SAS), as previously it exported to plain text.
Thus I create an SqlDataAdapter "da" by executing a rather complicated query( _sqlCommand) from a connection to an SQL Server(defined in _connection).
Later I fill the table dataTable with the result from that query. That part is fine as I can see in the debug the expected result. My next step would be to "export" dataTable into an ODBC(SAS) table with the same extructure. Therefore my idea was to create another query into sbInsertCommand 2, which transfers the records from "dataTable" to my target table "Baseline2" (in "Demo" directory, as used in SAS). Odviously has this construct an error(probably the [dataTable] reference) that I get when executing the last row.

Can anybody help me on how to build that query properly?

Expand|Select|Wrap|Line Numbers
  1.  //***** This is your table to hold the result set:
  2.             DataTable dataTable = new DataTable();
  3.  
  4.             try
  5.             {
  6.  
  7.                 //***** This is your data adapter that understands SQL databases:
  8.                 SqlDataAdapter da = new SqlDataAdapter(_sqlCommand, _connection);
  9.  
  10.                 _connection.Open();
  11.  
  12.                 //***** Fill the data table with select statement's query results:
  13.                 //***** dataTable will be used one step later in the query executed with ExecuteScalar()
  14.  
  15.                 int recordsAffected = da.Fill(dataTable);
  16.  
  17.                                 StringBuilder sbInsertCommand2 = new StringBuilder();
  18.                 sbInsertCommand2.Append("INSERT INTO Demo.");
  19.                 sbInsertCommand2.Append("Baseline2");
  20.                 sbInsertCommand2.Append(" select * from [dataTable]");
  21.  
  22.                 _insertCommand2 = new OdbcCommand(sbInsertCommand2.ToString(), _sasConnection);
  23.  
  24.  
  25.                 _insertCommand2.ExecuteScalar();
Oct 23 '08 #1
0 1730

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6256
by: Melanie | last post by:
Hi For my company I work for I have to read and process files from Excel, Access or MS SQL. This way is no poblem. I use the JDBC/ODBC bridge to make a delimited file (*.csv) and work with that. But now I have to export the processed delimited files back to an Excel file, Access file or in MS SQL. How this will work? Is their a way to use also the JDBC/ODBC bridge? Has anyone some links or tutorials?
6
18713
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
0
5025
by: Lewt | last post by:
I am aware of the 'hack the registry' approach. This is just not a safe way to accomplish this on a user's PC. I need to do this the right way. Is there anyone -perhaps from Microsoft - out there who can assist me on this? "Colin Stutley" wrote: > I now see your dilemma. > > Not sure of the appropiate API calls, but an alternative may be to simple > add the appropiate registry entries for the DSN. I would try; > 1) Export your...
3
3472
by: downwitch | last post by:
Hi, I'm having trouble getting data in ADO.Net recordsets. (VS 2005, SQL Server 2005). All my rowsets come back empty--whether sourced from queries or stored procs--despite ODBC connections with the same user credentials (two different UID/PWDs tried) returning existing data without a problem (i.e. it's not a SQL security problem). With code like
7
3051
by: Salad | last post by:
I am converting an application from A97 to A2003. I have 2 tables created by another application as a Foxpro.dbf. The table has no index. The connect string in A97 is FoxPro 2.0;HDR=NO;IMEX=2;DATABASE=C:\Test It's really easy to connect to those tables in A97. I'm having difficulties in A2003. I'm trying to follow the instructions in http://support.microsoft.com/kb/824264/.
1
2766
by: Bob | last post by:
I have a application that links to several sql tables. To improve performance I want to have a seperate database with an autoexec macro that when opened, connects to a ODBC data source and export three SQL tables overwriting the previously exported tables. Once that is completed, I want to export those tables into my working database. I want to set up the database to run with task manager (or something like it) to run every night. ...
9
10209
by: Bob Sanderson | last post by:
I'm trying to export a table to an ODBC database using a VBA subroutine. I have tested the ODBC setup manually and it works fine but when I try to do it with VBA, I get a "connection failed" error. This is the code I'm using. Can anyone tell me what is wrong with it? DoCmd.TransferDatabase acExport, "ODBC Database", "ODBC;DSN=*****;UID=*****;LANGUAGE=us_english;" & "DATABASE=*****", acTable, "Test", "Test" Thanks in advance.
3
4556
by: Edward Reid | last post by:
OK, I've been watching my DB grow and have known for a long time I would have to move the back end, but of course I waited until I started getting odd behavior (at about 1.92GB). So today I installed MySQL and (after a bit too much time getting the data source working) started exporting tables. I successfully exported eight of my nine tables, and can view them from a linked Access front end. But when I tried to export the final table,...
4
1804
by: Jeff | last post by:
I need to export MySQL data to Access. As always, there seems to be more than one way to do this. I notice that PHP has: DB.php If I was doing this in perl, there would be an ODBC driver (DBD::ODBC). Is there such a thing in PHP? Can this play well with DBO? I see some commercial driver products, but my needs are modest as I'm
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8680
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.