Managed C++ and ADO 
Author Message
 Managed C++ and ADO

Hi,

Is it possible to connect to a SQL database using managed
c++ code.  I am getting all sorts of errors with regards
to __gc data type conversions etc etc.

Anyone willing to share some code that connects to a sql
database to do a simple insert and select?

tia

regards
Nish



Sat, 23 Jul 2005 22:14:41 GMT  
 Managed C++ and ADO
Nish,

Quote:
> Is it possible to connect to a SQL database using managed
> c++ code.  I am getting all sorts of errors with regards
> to __gc data type conversions etc etc.

> Anyone willing to share some code that connects to a sql
> database to do a simple insert and select?

Here's some sample code that will show all records in one of the SQL Server
demo databases (pubs):

#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;

int main()
{
   //
   // Select all rows in jobs table of pubs
   //

   String* CONN_STRING = S"Data Source=localhost; Initial Catalog=pubs;
Integrated Security=SSPI";

   SqlConnection* conn = new SqlConnection(CONN_STRING);
   try
   {
      DataSet* set = new DataSet();
      SqlDataAdapter* adapter = new SqlDataAdapter(S"SELECT * FROM jobs",
conn);
      adapter->Fill(set);

      DataTable* table = set->Tables->Item[S"Table"];
      for ( int i=0; i < table->Rows->Count; i++ ) {
         DataRow* row = table->Rows->Item[i];
         Console::WriteLine(S"{0}\t{1}\t{2}\t{3}", row->Item[0],
                                                   row->Item[1],
                                                   row->Item[2],
                                                   row->Item[3]);
      }
   } __finally {
      conn->Close();
   }

Quote:
}

--
Tomas Restrepo



Sun, 24 Jul 2005 01:59:31 GMT  
 Managed C++ and ADO
Thank you...
Quote:
>-----Original Message-----
>Nish,

>> Is it possible to connect to a SQL database using
managed
>> c++ code.  I am getting all sorts of errors with regards
>> to __gc data type conversions etc etc.

>> Anyone willing to share some code that connects to a sql
>> database to do a simple insert and select?

>Here's some sample code that will show all records in one
of the SQL Server
>demo databases (pubs):

>#using <mscorlib.dll>
>#using <System.dll>
>#using <System.Data.dll>
>#using <System.Xml.dll>

>using namespace System;
>using namespace System::Data;
>using namespace System::Data::SqlClient;

>int main()
>{
>   //
>   // Select all rows in jobs table of pubs
>   //

>   String* CONN_STRING = S"Data Source=localhost; Initial
Catalog=pubs;
>Integrated Security=SSPI";

>   SqlConnection* conn = new SqlConnection(CONN_STRING);
>   try
>   {
>      DataSet* set = new DataSet();
>      SqlDataAdapter* adapter = new SqlDataAdapter

(S"SELECT * FROM jobs",

- Show quoted text -

Quote:
>conn);
>      adapter->Fill(set);

>      DataTable* table = set->Tables->Item[S"Table"];
>      for ( int i=0; i < table->Rows->Count; i++ ) {
>         DataRow* row = table->Rows->Item[i];
>         Console::WriteLine(S"{0}\t{1}\t{2}\t{3}", row-
>Item[0],
>                                                   row-
>Item[1],
>                                                   row-
>Item[2],
>                                                   row-
>Item[3]);
>      }
>   } __finally {
>      conn->Close();
>   }
>}

>--
>Tomas Restrepo

>.



Sun, 24 Jul 2005 13:14:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. using Managed dlls from Managed C++

2. Using ADO 2.1 / ADOX / ADO 2.0 with C++

3. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

4. Performance of unmanaged C++ in a managed C++ app

5. Redirected - Managed C++, differences from standard C++

6. Fatal Error C1010 in Mixing Managed C++ and Unmanaged C++ Code

7. Inherit unmanaged c++ classes from .Net platform (managed c++ or c#)

8. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

9. managed c++ vs unmanaged c++

10. How to pass a function pointer from Managed C++ to unmanaged c++

11. Managed C++ and Unmanaged C++ and Inheritance

12. Interoperability UnManaged C++, Managed C++, C#

 

 
Powered by phpBB® Forum Software