I added a column to a table, but, I can't see it.

furjaw

Member
Joined
Jun 10, 2006
Messages
17
Programming Experience
Beginner
I ran the code below that adds a column to an SQL table.
I refreshed Data Sources, but, the new column does not appear.
I refreshed Server Explorer and the new column does not appear.
I tried running the code again and I got:
"Column names in each table must be unique. Column name 'CaseNbr' in table 'Patient' is specified more than once."
so the column did actually get added, but, I can't see it.

Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sqlConnection As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Patient.mdf;Integrated Security=True;User Instance=True")
Dim str As String = "ALTER TABLE Patient ADD CaseNbr Varchar(50)"
Dim command As New System.Data.SqlClient.SqlCommand(str, sqlConnection)
sqlConnection.Open()
command.ExecuteNonQuery()
sqlConnection.Close()
Close()
End Sub
End Class
 
OK, so you added it to the database.. are you expecting it to show up in your dataset automatically? Why are you expecting this?
 
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.
Now, how do I get it to appear in Data Sources of Solution Explorer.
 
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).


I dont recommend that you link server explorer to the output database. Link it to the clean development version instead. For more info, read the DNU link in my signature; it discussed a specific problem but the supporting info is what you need to know :)

Now I can see the new column in Server Explorer.
Now, how do I get it to appear in Data Sources of Solution Explorer.
Data Sources has nothing at all to do with databases. It is purely for the datasets that your project has, which may or may not be based on all, some or none of a database's tables, views or stored procedures. :)

You can have a dataset that is nothing to do with a database
You can have a dataset's datatable that has more or less columns than a database table to which it represents
You may have set up a tableadapter with: SELECT * FROM table, but the * HAS to be expanded at design time into a list of column names. Add a new column to the db, it wont change the tableadapter's select list!

Hopefully this will help you understand how disconnected data architectures are to be maintained..
 
Back
Top