0

I am interested in a minimal set of instructions that allow me to add a column into an existing table in visual basic using ado.net components. My database is made in sql server. I would greatly appreciate a practical commentary to the code as that works best for me

edit 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

Here's a set of instructions meant for testing purposes and some wishful coding

Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
morgred
  • 969
  • 5
  • 15
  • 26

1 Answers1

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

comm.ExecuteNonQuery()

I would also suggest using a using statement to automatically dispose of objects.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • http://stackoverflow.com/questions/376068/does-end-using-close-an-open-sql-connection – Mitch Wheat Feb 20 '13 at 04:02
  • and a rather fine suggestion. i was trying to immitate an example and i became confused when autocomplete didnt give me the execute non query method. using would have solved that i guess, it all makes sense now – morgred Feb 20 '13 at 04:05