Sir
I am creating table in sql database at runtime, but i want to add more columns to that
table which i created at runtime. Below is the code for creating my table:-
Private Sub Sql_Dept()
Dim conStr As String = "Server=.;Database=PMS;Integrated Security = True;MultipleActiveResultSets=True;"
Dim objCon As New SqlConnection(cnSettings2)
Dim obj As SqlCommand
Dim strSQL As String
Dim myReader As SqlDataReader
objCon.Open()
obj = objCon.CreateCommand()
Try
strSQL = "SELECT * FROM sysobjects WHERE name='Dept'"
obj.CommandText = strSQL
myReader = obj.ExecuteReader()
If Not myReader.Read() Then
myReader.Close()
strSQL = "CREATE TABLE Dept (Dept_No INT PRIMARY KEY, Dept_Name varchar(20), Flag varchar(2))"
obj.CommandText = strSQL
obj.ExecuteNonQuery()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
objCon.Close()
objCon = Nothing
End Sub
This table was created successfully in database, how can add more columns to this table if columns are not exists here at runtime. I want to add three columns name like Flg2,Flg3 and Flg4 etc.
Can some one tell were i need to change in above code for this addition of columns.Please help me with codes.