但现在......
我想使用带有按钮的文本框删除或删除表格。
如何删除我创建的表格
这是我的代码:
Imports System.Data.OleDb
Public Class Form1
Dim conn As New OleDbConnection
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
'Create Table
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=masterlist.accdb"
Using con As New OleDbConnection(connectionString)
con.Open()
Using cmd As New OleDbCommand()
cmd.Connection = con
cmd.CommandText = " CREATE TABLE " & txtID.Text & " (ID COUNTER, [Name] INTEGER) "
Try
cmd.ExecuteNonQuery()
Console.WriteLine("Table created.")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
con.Close()
End Using
End Sub
'Delete table?
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=database\masterlist.accdb"
Using con As New OleDbConnection(connectionString)
con.Open()
Using cmd As New OleDbCommand()
cmd.Connection = con
cmd.CommandText = " DROP TABLE " & txtID.Text
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
Console.WriteLine("Table drop.")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
con.Close()
End Using
End Sub
End Class
先谢谢你
答案 0 :(得分:0)
尝试使用con替换:Dim con 要么 添加另一个n到con con = conn你忘记了一个