add column to an existing ms database permanently

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ksary
    New Member
    • Oct 2013
    • 1

    add column to an existing ms database permanently

    Hello everyone I need help with adding a column in ms access database and update it with a value.Here is my code, it gives an error that says syntax error in field definition.plea se correct me.

    Code:
    string myConn = " ";
    
    myConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb";
    
    OleDbConnection myCon = new OleDbConnection(myConn);
    
    string myInsert = "ALTER TABLE Attendance ADD COLUMN SignIn" + dateTimePicker1.Value;
                    
    OleDbCommand myCom = new OleDbCommand(myInsert);
    myCom.Connection = myCon;
    
    myCon.Open();
    try
    {
     myCom.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
     MessageBox.Show(ex.Message.ToString());
    }
    myCon.Close();
                }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You didn't give the new column a data type. And I assume your date time picker value is what you want to use as the default value for that column. You need to use the default keyword to do that.

    Comment

    Working...