473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# SqlDataAdapter to ODBC export

1
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 sbInsertCommand2, 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 1718

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

Similar topics

0
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....
6
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
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...
3
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...
7
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...
1
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...
9
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....
3
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.