vb.net create table
时间: 2024-01-18 09:17:38 浏览: 35
在VB.NET中创建表格可以使用ADO.NET来实现。以下是一个示例代码:
```vb
Imports System.Data.SqlClient
Public Class Form1
Private Sub btnCreateTable_Click(sender As Object, e As EventArgs) Handles btnCreateTable.Click
Dim connectionString As String = "Data Source=YourServerName;Initial Catalog=YourDatabaseName;Integrated Security=True"
Dim tableName As String = "YourTableName"
Using connection As New SqlConnection(connectionString)
connection.Open()
Dim createTableQuery As String = "CREATE TABLE " & tableName & " (ID INT PRIMARY KEY, Name VARCHAR(50), Age INT)"
Dim command As New SqlCommand(createTableQuery, connection)
command.ExecuteNonQuery()
MessageBox.Show("Table created successfully.")
connection.Close()
End Using
End Sub
End Class
```
这段代码使用了`SqlConnection`类来建立与数据库的连接,并使用`SqlCommand`类执行SQL语句来创建表格。你需要将`YourServerName`替换为你的服务器名称,`YourDatabaseName`替换为你的数据库名称,`YourTableName`替换为你想要创建的表格名称。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)