Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++->SQL connection 1

Status
Not open for further replies.

michaelkrauklis

Programmer
Joined
Dec 5, 2001
Messages
226
Location
US
I've created a data structure in my program that basically represents a table. Now I need to be able to port it directly to SQL Server 2k. I think the simplest way is going to be to create a connection and just call sql commands to create/modify tables but is there an easy way to do this? I've checked out ole db, ado, and odbc connections but I can't seem to get any good answers. All the examples I get are terribly complicated and don't work when I try them. I have a few books but they don't seem to be much help either. Any advice would be greatly appreciated. thanks MYenigmaSELF
myenigmaself@yahoo.com
 
Does the database (empty or not) exist already or not?

Matt
 
Yes. The database exists, and another thing I'd need to do is drop all the tables in it each time I do this process so it would be empty. MYenigmaSELF
myenigmaself@yahoo.com
 
if you create an odbc source for the database then you could

Code:
CDatabase db;
db.Open(<odbc name>);
db.BeginTrans();
CString SQL;
SQL.Format(&quot;CREATE TABLE ....&quot;);
db.ExecuteSQL(SQL);
db.CommitTrans();


// if tables already exist in the database
// you can insert a class into your project
// that would be derived from CRecordset
// that would look like:

CDatabase db;
db.Open(<odbc name>);
MyRecordset rs(&db);

I dont know if this is along the lines you were looking for

Matt

 
That's exactly what I was looking for. I've already created the odbc source. I knew there had to be a simple way to do this. I just hope it's fast enough. Speed is an issue, and from what I've read ole db is faster. But thanks. This'll keep me going for a while. MYenigmaSELF
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top