|
-
Oct 25th, 2024, 04:31 AM
#1
Thread Starter
Hyperactive Member
VB2017 Ado.net SqlExpress. Problem with Table Creation, no error but does'nt work
I have two weeks to develop this little program. The program will create an SQL Database and a table. It does not show any error, but when I compile or debug, it does nothing. I appreciate your help in advance about this matter. Here is the code.
Imports System.Data.SqlClient
Public Class Form1
Private objCon As Object
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnCreateDatabase_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BtnCreatedatabase.Click
Dim str As String
Dim myConn As SqlConnection = New SqlConnection("Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True; ")
str = "CREATE DATABASE visitas ON PRIMARY " &
"(NAME = MyDatabase_Data, " &
" FILENAME = 'C:\Project\visitas.mdf', " &
" SIZE = 2MB, " &
" MAXSIZE = 10MB, " &
" FILEGROWTH = 10%)" &
" LOG ON " &
"(NAME = MyDatabase_Log, " &
" FILENAME = 'C:\Project\visitasLog.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
'Create a table
' = "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True; "
myConn = New SqlConnection(constr)
myConn.Open()
myCommand = objCon.CreateCommand()
Dim strSQL As String
strSQL = "CREATE TABLE Names (LastName VARCHAR(30), FirstName VARCHAR (30))"
' Execute
myCommand.CommandText = strSQL
Try
myCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
myConn.Close()
myConn = Nothing
End Sub
Private Function constr() As String
Throw New NotImplementedException()
End Function
Private Function strcoon() As String
Throw New NotImplementedException()
End Function
End Class
Tags for this Thread
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
|