SQL anyone ?
-
So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
-
So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
1. System.Data.OleDbClient 2. SqlConnection,SqlCommand and OleDbConnection,OleDbCommand can execute SQL statements. You can use an OleDbDataReader (SQlDataReader if MSSQL) to retun records in a fast forwar-only cursor and do as you wish with the data. xxxCommand and xxxConnection can also execute quries that have no return data or onlay a single scalar value. Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
-
So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
Look at the
System.Data.Odbc
(only in 1.1) andSystem.Data.OleDb
namespaces for setting up connections and executing commands etc. The OdbcCommand and OleDbCommand objects both have theExecuteNonQuery
method (and more) to execute SQL statements without involving DataSet and DataTable objects... -
So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
While the previous answers were complete and technically correct, why do I still have the feeling you are using the wrong tool for the job? You can do it on anything you choose - from .bat to .net - A customer
-
1. System.Data.OleDbClient 2. SqlConnection,SqlCommand and OleDbConnection,OleDbCommand can execute SQL statements. You can use an OleDbDataReader (SQlDataReader if MSSQL) to retun records in a fast forwar-only cursor and do as you wish with the data. xxxCommand and xxxConnection can also execute quries that have no return data or onlay a single scalar value. Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
Thanks Rob, but that's not exactly what I was looking for. I suspect I'll end up moving to C++ one way or the other :-) Thanks again, F.O.R.
-
Look at the
System.Data.Odbc
(only in 1.1) andSystem.Data.OleDb
namespaces for setting up connections and executing commands etc. The OdbcCommand and OleDbCommand objects both have theExecuteNonQuery
method (and more) to execute SQL statements without involving DataSet and DataTable objects...Hmmm... ..I didn't know that 1.1 had an Odbc namespace! I'll take a look, thanks :-) F.O.R.
-
While the previous answers were complete and technically correct, why do I still have the feeling you are using the wrong tool for the job? You can do it on anything you choose - from .bat to .net - A customer
Because indeed I am. I am looking for something that has a 1:1 correspondence to the sql.h library from C/C++. Now, while C# has alternatiuve ways to achieve the same goals (all of the Data namespace, for instance), I am not surprized to find that C# keeps you away from such low level kind of stuff. It indeed makes much more sense for me to use a C++ (managed or not) app in this case, but I figured I could look around for a bit before giving up on being more modern :-) F.O.R.
-
So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
OK, before I give up on this, let me rephrapse the question :-) Any way I can stick in a C# App the following lines?
sqlr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &h_env); sqlr = SQLSetEnvAttr(h_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_UINTEGER);
and other statements like that ? They are taken from a C/C++ app that includes and . Maybe I can place them in an un-managed section? It would solve soooo many problems ! Thanks in advance for any input, F.O.R. -
OK, before I give up on this, let me rephrapse the question :-) Any way I can stick in a C# App the following lines?
sqlr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &h_env); sqlr = SQLSetEnvAttr(h_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_UINTEGER);
and other statements like that ? They are taken from a C/C++ app that includes and . Maybe I can place them in an un-managed section? It would solve soooo many problems ! Thanks in advance for any input, F.O.R.This is just a shot in the dark but you could take a look at addng a COM reference to the Microsoft SQLDMO Object Library. You might find what you need in there.