SQL Database manipulation

SimDuck

Member
Joined
Oct 25, 2004
Messages
21
Hi, I am trying to delete a database using the SQL query string "DROP DATABASE Copy of Account_Details". I have looked for some help but have been unable to find some.

Dim strConnString As New Connection
Dim strDir As New Directory
Dim strConn As String
Dim strCommand As String
strCommand = "DROP DATABASE Copy of Account_Details.mdb"
strConn = strConnString.ConString("copy of account_details.mdb", strDir.RootDir)
Dim myConnection As New OleDbConnection(strConn)
Dim myCommand As New OleDbCommand(strCommand, myConnection)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

When I get to the executenonquery command, I get an unhandled error in the dll.

What am I doing wrong and how do I successfully delete/ remove this database?

I am also trying to add new databases (sql = "CREATE DATABASE Test") using code but when the myconnection.open code is excecuted, I get an error saying the conenction is not open.

How do I create a database on the fly using sql code?

Thank you in advance for your answeres.
 
PlausiblyDamp said:
What database are you using? The .mdb looks like access - in which case this code will not work as it is specific to SQL Server.
I am trying to use an Access Databse, but I am not concerned with which type of database I use.

How do I create a SQL database via code as I dont have any 3rd party SQL Database software?

stustarz said:
If it is an access database then you can always use System.IO.File.Delete(PathAsString)

This will work if I want to delete the database, but how do I create one? I can use this to create but then when I try to connect to the database, I get an error.

Thank you again. :)
 
Back
Top