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
'Try
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()
'Catch
'End Try
Close()
End Sub
End Class
here it runs in query analyzer ...
u do try it..
it must work ..
|||YOu are using an user instance. Data Files of user instances in during development time will be overwritten everytime you start the application from Visual Studio if the setting of "Copy Always" is set to true. Disable this option in order to leave the change in the file.Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||I had everything set to Do Not Copy.|||If not error tis thrown, the column was created, try to select the information from the INFORMATION_SCHEMA.COLUMNS View after executing your code to create a new column, you will see that the column was added to the table. There has to be a misconfiguration of the deployment where the debug process always copy a new datafile to the directory.
Jens K. Suessmeyer.
http://www.sqlserver2005.de
No comments:
Post a Comment