Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Adding a column to an existing SQL database table

Status
Not open for further replies.

furjaw

Bioengineer
Jun 10, 2006
9
0
0
US
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#")
 
Replies continue below

Recommended for you

Case is a reserved word in MSSQL and MySQL. I would always avoid using reserved words as names for tables or fields, although technically you can provided they are properly delimited. Check out the help file for your particular version of SQL for details.

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 before posting
Steam Engine enthusiasts
Steam Engine Prints
 
I added the following statement to my program:

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
 
Here is how MSDN tells you to do it (I just added these statements to my Form Load routine):

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."
 
OK, I deleted the Patient.mdf in Server Explorer.
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?
 
Status
Not open for further replies.
Back
Top