Adding a column to an existing SQL database table
Adding a column to an existing SQL database table
(OP)
Visual Basic 2005
I used DataSet Designer to add a column called "Case#" to an existing SQL table.
The table is used by a DataGridView in a VB 2005 program.
I got it working on my development computer in debug mode.
Then, when I installed it, I got an exception "Case# is an invalid column" and none of my data records appeared.
Adding the following statement did not help:
PatientDataSet.Patient.Columns.Add("Case#")
I used DataSet Designer to add a column called "Case#" to an existing SQL table.
The table is used by a DataGridView in a VB 2005 program.
I got it working on my development computer in debug mode.
Then, when I installed it, I got an exception "Case# is an invalid column" and none of my data records appeared.
Adding the following statement did not help:
PatientDataSet.Patient.Columns.Add("Case#")





RE: Adding a column to an existing SQL database table
I would also normally avoid symbols and punctuation marks in SQL table or field names - stick to letters and numbers if you can.
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376: Eng-Tips.com Forum Policies before posting
Steam Engine enthusiasts
Steam Engine Prints
RE: Adding a column to an existing SQL database table
Me.PatientDataSet.Patient.Columns.Add("CaseNbr", Type.GetType("System.String"))
But it did not do anything.
I added the statement as the first command in the Form Load routine:
Public Class Patient
Public Sub Patient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PatientDataSet.Patient.Columns.Add("CaseNbr", Type.GetType("System.String"))
Me.PatientTableAdapter.Fill(Me.PatientDataSet.Patient)
PatientBindingSource.Position = Form1.DefaultPatient
End Sub
RE: Adding a column to an existing SQL database table
Dim columns As DataColumnCollection = Me.PatientDataSet.Patient.Columns
If columns.Contains("CaseNbr") Then
MsgBox("'CaseNbr' column already exists" )
Else
Me.PatientDataSet.Patient.Columns.Add("CaseNbr", Type.GetType("System.String"))
End If
It bombed out with this message:
"An attempt to attach an auto-named database for file
C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\
OrthoLabRx\OrthoLabRx\bin\Debug\Patient.mdf failed.
A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
RE: Adding a column to an existing SQL database table
Then I opened a New Connection and browsed to the .mdf file under the output directory (\bin\debug).
Now I can see the new column in Server Explorer.
But, how do I get it to appear in Data Sources of Solution Explorer?