manny cash
Member
- Joined
- Oct 19, 2024
- Messages
- 12
- Programming Experience
- Beginner
This little program checks if the database exists to delete with the message box option, yes or no. When I debug it, the program has no errors, but when I run it, it doesn't do anything and has no inconsistent messages. I use VB 2017, Sql Database. I am asking for help "cause I am just learning visual basic without a teacher. I appreciate your help guys.
VB.NET:
Imports System.Data.SqlClient
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(340, 189)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(227, 93)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As Button
'Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'End Sub
Public Shared Function CheckDatabaseExists(ByVal server As String,
ByVal database As String) As Boolean
Dim connString As String = ("Data Source=" _
+ (server + ";Initial Catalog=master;Integrated Security=True;"))
Dim Appoinment As String = Nothing
Dim cmdText As String =
("select * from master.dbo.sysdatabases where name=\’" + (Appoinment + "\’"))
Dim bRet As Boolean = False
Select Case MsgBox("Are you sure ?", MsgBoxStyle.YesNo, "Delete")
Case MsgBoxResult.Yes
' Do something if yes
Dim dropDatabaseQuery As String = "DROP DATABASE IF EXISTS Appoinment"
Case MsgBoxResult.No
' Do something if no
Try
Catch ex As exception
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Select
Using sqlConnection As SqlConnection = New SqlConnection(connString)
sqlConnection.Open()
Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
Using reader As SqlDataReader = sqlCmd.ExecuteReader
bRet = reader.HasRows
End Using
End Using
End Using
Return bRet
End Function
End Class
Last edited by a moderator: