Adding a data column

draget

New member
Joined
Nov 9, 2006
Messages
1
Hi, I have a script which executes perfectly with not errors, however it simply does not work!

Code:
 Dim cb As New OleDb.OleDbCommandBuilder(TableForm.da)

        Dim thenewcol As New System.Data.DataColumn

        thenewcol.ColumnName = nameofcol.Text

        TableForm.ds.Tables("PeriodicDB").Columns.Add(thenewcol)

        TableForm.da.Update(TableForm.ds, "PeriodicDB")

        TableForm.setup()

Code:
  Public Sub setup()

        ds.Clear()

        con.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0; DATA Source = " + path


        Try
            con.Open()
        Catch ex As Exception
            lblStatus.Text = "Error!"
            lblLink.Text = "Details..."
            exceptionText = ex.ToString()
            Return
        End Try

        sql = "SELECT * FROM PeriodicElements"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "PeriodicDB")

        sql = "SELECT * FROM data_inc"
        da2 = New OleDb.OleDbDataAdapter(sql, con)
        da2.Fill(ds, "ColNames")

        tot_columns = ds.Tables("PeriodicDB").Columns.Count

        lblStatus.Text = ("Connection to DB was successful.")
        lblLink.Text = ""

        con.Close()



    End Sub

As I said before, there are no errors, it simply doesnt work, the database remains unchanged.

One thing interesting to note, is that when setup recounts the columns, it includes the new column in its count, yet for all I can see it isnt in the database, and then my program crashes trying to access the item at the last count.

Any ideas?


Thanks,

Tom
 
To create a new column in the DataBase you cant use this way.
You have to use a normal SQL-Command like "ALTER TABLE ADD COLUMNNAME COLTYPE".
 
Back
Top