0

我对一组最少的指令感兴趣,这些指令允许我使用 ado.net 组件将列添加到 Visual Basic 中的现有表中。我的数据库是用 sql server 制作的。我将非常感谢对代码的实用评论,因为这对我最有效

编辑 1

Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim connString As String = "Data Source=THE_SHOGUNATE\SQLEXPRESS;Initial Catalog=le_database;Integrated Security=True"
        Dim conn As New SqlConnection(connString)
        conn.Open()
        Dim comm As New SqlCommand("SELECT denumire FROM Reparatii", conn)
        Dim reader As SqlDataReader = comm.ExecuteReader
        Dim dt As New DataTable
        dt.Load(reader)
        ListBox1.DataSource = dt
        ListBox1.DisplayMember = "denumire"
        conn.Close()

        conn.Open()
        Dim comm As New SqlCommand("ALTER TABLE reparatii ADD durata_executie INT", conn)

        conn.Close()
    End Sub
End Class

这是一组用于测试目的的说明和一些如意的编码

4

1 回答 1

2
conn.Open()
Dim comm As New SqlCommand("ALTER TABLE reparatii ADD durata_executie INT", conn)

comm.ExecuteNonQuery()

我还建议使用using语句来自动处理对象。

于 2013-02-20T03:57:46.540 回答