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

2
  • there. what do i do now? Commented Feb 20, 2013 at 3:56
  • duplicate to users other question stackoverflow.com/q/14971233/1606972 Commented Feb 20, 2013 at 14:36

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.