|
-
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.
-
Sep 11th, 2006, 08:15 AM
#2
Re: creating database programmatically using ADO.NET and VB.NET
Fix the first issue and you fix the others. You have to put the imports at the very top of the code file. The only lines that can precede the imports are comments and Option settings. Once you fix that the import will be recognised and the other errors will disappear.
-
Sep 11th, 2006, 05:24 PM
#3
Thread Starter
Junior Member
Re: creating database programmatically using ADO.NET and VB.NET
Thank You For Help Buddy.
-
Sep 11th, 2006, 06:52 PM
#4
Re: creating database programmatically using ADO.NET and VB.NET
If your issue is resolved please use the Thread Tools menu to mark the thread as such.
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
|