Adding a New Column in MS Access within VB

databases Egypt
  • 12 years ago

    The system I am working on involves sales transaction and I want it to show not only the total payments but also the smaller payments applied that made up the total. My solution would be that I'll make three columns, the first is the primary/reference key, the second column would be where the total payments would be saved, and the third woulld be where would I save the smaller payments. I would like the third column to be replicated (the added column should have the same properties as the third), although I'm not sure if adding a column can be done. I know the code Data.Recordset.Addnew adds a new row, but I don't know a code for adding a column.

     What could be the best solution for this?

  • 12 years ago

    Which version of VB are you using?

    I appreciate that this is C#, but it may help you:

    string commandString = "ALTER TABLE " + TableName + " ADD COLUMN " + FieldName + " " + Type;

    OleDbConnection Conn = new OleDbConnection( your connection );


    OleDbCommand Command = new OleDbCommand(commandString, Conn);


    Where TableName, FieldName and Type are all strings.  More about Type can be found here:

    You may like to add an exception handler around the .ExecuteNonQuery and handle it accordingly.


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov