|
-
Jun 1st, 2007, 10:07 AM
#1
Thread Starter
PowerPoster
create sql database from txt file via visual basic (6.0)
Admit have a txt file similar:
filed1 filed2
aaaaaaaaaa bbbbbbbbbbbbbb
cccccccccccc dddddddddddddd
.............
yyyyyyyyyy zzzzzzzzzzzzzz
How to create VIA VISUAL BASIC (ADO or DAO) a new SQL Server databse?
... in effect i want to create a database and table with 2 fileds and import data from txt file "ex novo"...
found thsi but vb.net and ado.net:
http://support.microsoft.com/kb/305079
-
Jun 1st, 2007, 10:28 AM
#2
Re: create sql database from txt file via visual basic (6.0)
The method is very similar... the SQL string is the same (tho I presume you want different fields etc, so see the SQL tutorials in our Database FAQs), you just need to connect to the database (and execute the query) using the usual syntax.
Using ADO, that could be:
Code:
Dim myConn As ADODB.Connection
Set myConn = New ADODB.Connection
myConn.Open "Driver={SQL Server};Server=(local)\netsdk;" & _
"uid=sa;pwd=;database=master"
str = "CREATE DATABASE ... "
myConn.Execute str
myConn.Close
set myConn = Nothing
Note that this is not a ideal example - you should add error handling etc.
-
Jun 1st, 2007, 10:44 AM
#3
Re: create sql database from txt file via visual basic (6.0)
And, even though the code is for .NET, you can use the CREATE DATABASE query from that example as a starting point for setting yours up.
-
Jun 1st, 2007, 11:11 AM
#4
Thread Starter
PowerPoster
Re: create sql database from txt file via visual basic (6.0)
 Originally Posted by si_the_geek
The method is very similar... the SQL string is the same (tho I presume you want different fields etc, so see the SQL tutorials in our Database FAQs), you just need to connect to the database (and execute the query) using the usual syntax.
Using ADO, that could be:
Code:
Dim myConn As ADODB.Connection
Set myConn = New ADODB.Connection
myConn.Open "Driver={SQL Server};Server=(local)\netsdk;" & _
"uid=sa;pwd=;database=master"
str = "CREATE DATABASE ... "
myConn.Execute str
myConn.Close
set myConn = Nothing
Note that this is not a ideal example - you should add error handling etc.
hI all
Tks for sugestion.
My friend suggest me to use SQL DMO object in VB to create database and table, wath you think?
In other case admit i have created a db and table how to insert value from txt into the new sql database?
...
-
Jun 1st, 2007, 11:16 AM
#5
Re: create sql database from txt file via visual basic (6.0)
SQL DMO is certainly a valid option - but I'm afraid I can't help you with that, as I don't use it myself (so the code works for other DBMS's, I've only ever used Create statements, or occasionally ADOX).
To add data once the table have been created, use the usual methods - if you are using ADO, there are examples in this FAQ article.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|