My program has an access database with a table called "Contacts". This table stores many values. I have a seperate table that stores surveys. Each contact should have a column for every survey, indicating whether or not the survey has been completed. However, this means I need to add columns to the database while the program is running. I tried the following code, which runs WITHOUT errors, but does not seem to actually add the column. Could someone please tell me what I am doing wrong?
Code:contactsDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM Contacts", frmAdmin.con) contactsCommandBuilder = New OleDb.OleDbCommandBuilder(contactsDataAdapter) dtContacts.Clear() contactsDataAdapter.Fill(dtContacts) drContacts = dtContacts.Rows(0) Dim intRowPosition = 0 surveysDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM Surveys", frmAdmin.con) surveysCommandBuilder = New OleDb.OleDbCommandBuilder(surveysDataAdapter) dtSurveys.Clear() surveysDataAdapter.Fill(dtSurveys) Dim intRowPosition2 = 0 frmAdmin.con.Open() Dim Survey As DataColumn = New DataColumn(txtName.Text) 'declaring a column named Survey Survey.DataType = System.Type.GetType("System.Boolean") 'setting the datatype for the column dtContacts.Columns.Add(Survey) 'adding the column to table dtContacts.AcceptChanges() contactsDataAdapter.Update(dtContacts) While dtContacts.Rows.Count <> intRowPosition drContacts = dtContacts.Rows(intRowPosition) drContacts(txtName.Text) = False intRowPosition += 1 End While Dim temp As Integer drSurveys = dtSurveys.NewRow() drSurveys.Item("ID") = txtName.Text temp = txtGold.Text drSurveys.Item("GoldReward") = temp temp = txtExperience.Text drSurveys.Item("ExperienceReward") = temp drSurveys.Item("Expiration") = dtpExpiration.Value.Date dtSurveys.Rows.Add(drSurveys) contactsDataAdapter.Update(dtContacts) surveysDataAdapter.Update(dtSurveys) frmAdmin.con.Close()




Reply With Quote