|
-
Sep 11th, 2006, 07:11 AM
#1
Thread Starter
Junior Member
creating database programmatically using ADO.NET and VB.NET
Hi
i am using VB.NET 2005 i tried to creat data base file by using this code but i got 3 errors as the follow
1 'Imports' statements must precede any declarations.
2 Type 'SqlConnection' is not defined.
3 Type 'SqlCommand' is not defined.
i need help can any perfect programmer tell me what is the wrong with this way?
here is the code:
Imports System.Data.SqlClient
-----------------------------
Dim str As String
Dim myConn As SqlConnection = New SqlConnection("Server=(local)\netsdk;" & _
"uid=sa;pwd=;database=master")
str = "CREATE DATABASE MyDatabase ON PRIMARY " & _
"(NAME = MyDatabase_Data, " & _
" FILENAME = 'D:\MyFolder\MyDatabaseData.mdf', " & _
" SIZE = 2MB, " & _
" MAXSIZE = 10MB, " & _
" FILEGROWTH = 10%) " & _
" LOG ON " & _
"(NAME = MyDatabase_Log, " & _
" FILENAME = 'D:\MyFolder\MyDatabaseLog.ldf', " & _
" SIZE = 1MB, " & _
" MAXSIZE = 5MB, " & _
" FILEGROWTH = 10%) "
Dim myCommand As SqlCommand = New SqlCommand(str, myConn)
Try
myConn.Open()
myCommand.ExecuteNonQuery()
MessageBox.Show("Database is created successfully", _
"MyProgram", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
If (myConn.State = ConnectionState.Open) Then
myConn.Close()
End If
End Try
-----------------------------
i got this code from MS support site here is the link.
http://support.microsoft.com/default...US;Q305079#top
Thanks
Last edited by code hunter; Sep 11th, 2006 at 07:17 AM.
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
|