Linkin C++ Files to a database

i need some information on how to implement a C++ programme to coressp

Page 1 of 1

5 Replies - 1258 Views - Last Post: 10 March 2009 - 08:07 PM Rate Topic: -----

#4 Magnet  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: Linkin C++ Files to a database

Post icon  Posted 09 March 2009 - 10:19 PM

hey Programmers i have moved on to C++ :D , but i need some info on how to link a C++ programme to Mircosoft Access instead of a text file.
I have tried googlin it but it doesnt seem to be givin me the relivant info i need.
plz any suggestion is greatly appreciated.
thank u.

This post has been edited by Magnet: 10 March 2009 - 07:41 AM

Was This Post Helpful? 1

#8 Magnet  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: Linkin C++ Files to a database

Posted 10 March 2009 - 07:57 AM

can anyone verify this code?

Dim mycon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DEsign.accdb"
Dim customer As String = "select * from Customer_tbl"
Dim Notes As String = "select * from Notes_tbl"
Dim con As New OleDb.OleDbConnection(mycon)
Dim comCustomer As New OleDb.OleDbCommand(customer, con)
Dim comdNotes As New OleDb.OleDbCommand(Notes, con)
Dim Custsql As String = "first name,Last Name"
Dim Sql As String = "insert into Customer_tbl (Custsql )values '" & txtFirstName.Text & "','" & txtLastName.Text & "')"
comCustomer = New OleDb.OleDbCommand(Sql, con)

con.Open()
comCustomer.ExecuteNonQuery()
comCustomer.Dispose()
con.Close()

This post has been edited by Magnet: 10 March 2009 - 07:57 AM

Was This Post Helpful? 1

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: Linkin C++ Files to a database

Posted 10 March 2009 - 09:13 AM

That code is Visual Basic. Is that your intention?

If you're looking for database connection strings, try here.
Was This Post Helpful? 0
  • +
  • -

#10 tjust80  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 73
  • Joined: 01-December 08

Re: Linkin C++ Files to a database

Posted 10 March 2009 - 09:46 AM

you need to do following ???

1- create new ODBC system DSN from ODBC data source administrator.
2- use the DSN name in your application.
3- write your application to connect to th DSN name. may be u can use sequence of functions started with SQLAllocHandle function

following sample from msdn

SQLHENV	 henv;
SQLHDBC	 hdbc;
SQLHSTMT	hstmt;
SQLRETURN   retcode;

	  /*Allocate environment handle */
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
   /* Set the ODBC version environment attribute */
   retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 

   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
	  /* Allocate connection handle */
	  retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 

	  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
		 /* Set login timeout to 5 seconds. */
		 SQLSetConnectAttr(hdbc, (void*)SQL_LOGIN_TIMEOUT, 5, 0);

		 /* Connect to data source */
		 retcode = SQLConnect(hdbc, (SQLCHAR*) "Sales", SQL_NTS,
				  (SQLCHAR*) "JohnS", SQL_NTS,
				  (SQLCHAR*) "Sesame", SQL_NTS);

		 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
			/* Allocate statement handle */
			retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 

			if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
			/* Process data */
				 ;
				 ;
				 ;

			   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
			}
			SQLDisconnect(hdbc);
		 }
		 SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
	  }
   }
   SQLFreeHandle(SQL_HANDLE_ENV, henv);



Was This Post Helpful? 0
  • +
  • -

#11 Magnet  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: Linkin C++ Files to a database

Posted 10 March 2009 - 08:01 PM

View PostJackOfAllTrades, on 10 Mar, 2009 - 08:13 AM, said:

That code is Visual Basic. Is that your intention?

If you're looking for database connection strings, try here.



well i'm using microsoft visual c++ 2005 Express edition. is that what you're refferin to?
Was This Post Helpful? 0
  • +
  • -

#12 Magnet  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: Linkin C++ Files to a database

Posted 10 March 2009 - 08:07 PM

View Posttjust80, on 10 Mar, 2009 - 08:46 AM, said:

you need to do following ???

1- create new ODBC system DSN from ODBC data source administrator.
2- use the DSN name in your application.
3- write your application to connect to th DSN name. may be u can use sequence of functions started with SQLAllocHandle function

following sample from msdn

SQLHENV	 henv;
SQLHDBC	 hdbc;
SQLHSTMT	hstmt;
SQLRETURN   retcode;

	  /*Allocate environment handle */
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
   /* Set the ODBC version environment attribute */
   retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 

   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
	  /* Allocate connection handle */
	  retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 

	  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
		 /* Set login timeout to 5 seconds. */
		 SQLSetConnectAttr(hdbc, (void*)SQL_LOGIN_TIMEOUT, 5, 0);

		 /* Connect to data source */
		 retcode = SQLConnect(hdbc, (SQLCHAR*) "Sales", SQL_NTS,
				  (SQLCHAR*) "JohnS", SQL_NTS,
				  (SQLCHAR*) "Sesame", SQL_NTS);

		 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
			/* Allocate statement handle */
			retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 

			if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
			/* Process data */
				;
				;
				;

			   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
			}
			SQLDisconnect(hdbc);
		 }
		 SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
	  }
   }
   SQLFreeHandle(SQL_HANDLE_ENV, henv);






Thanks you for u contribution but i'm havin a hard time understandin the code......should i jus copy the code into my programme?

could u give me a quick tutorial on the process i should go through...
thank u
Was This Post Helpful? 1

Page 1 of 1