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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create database programmatically

Status
Not open for further replies.

Wolfie7873

Technical User
Jan 15, 2004
94
US
Trying to find a simple snippet to create a database from within a program.

I'm relatively new to databases, but i'm picking up fast. I know all of the basic SQL commands and how to implement them once I have an open connection to an existing database, but what I would like is something like this:

CREATE_DBV4=<user defined path>;
OleDbConnection * cnDirector = new OleDbConnection;
cnDirector->ConnectionString =
S" Provider=Microsoft.Jet.OLEDB.4.0;"
S"Data Source=<path>";
cnDirector->Open();
OleDbCommand * cmDirector = new OleDbCommand(S"CREATE TABLE <etc>",cnDirector);

and continue from there. I don't quite get how/where the first CREATE command works. Where exactly does it go in relation to the connection directive?

Thanks in advance...

 
I'm not sure I understand what you mean. This is not a network application. The program and the created database will live on the user's machine. What do you mean by connect to the server first?
 
i mean you call Connect method and then call Execute on corresponding classes...whether the database server is local or on a network doesnt matter

------------------------
 
I'm afraid I still need a little more help. Do I need any additional namespaces besides System, System::Data, and System::Data:OleDb ?

What's the syntax for connecting to the server in this case?
 
i am using odbc so here ms.data.odbc is used,
basically you will use syntax much like this

Code:
using System;
using System.IO;
using System.Collections;
using System.Data;
using Microsoft.Data.Odbc;
using System.Windows.Forms;
using System.Reflection;

(...)
MyConString = String.Format("DRIVER={{MySQL ODBC 3.51 Driver}};" + 
"SERVER={0};" +
"DATABASE={1};" +
"UID={2};" +
"PASSWORD={3};" +
"OPTION=3", srvName, dbName, user, password);
sr.Close()

------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top