Link to home
Start Free TrialLog in
Avatar of wjstarck
wjstarck

asked on

Help adding a field to MySQL table in C#

Hello-

I need the proper syntax to add a field to an existing mySQL table in C#/.NET 3.5 SP1. I have tried ALTER TABLE and UPDATE TABLE but I apparently don't have the proper syntax. So, for a table I created thusly,

            private void To6_2_0() {
                  if(FromVersion<new Version("6.2.0.0")) {
                        string command;
                        if(DataConnection.DBtype==DatabaseType.MySql) {

                    command = "DROP TABLE IF EXISTS anesthmedsintake";
                    General.NonQ(command);
                    command = @"CREATE TABLE anesthmedsintake(
                                    AnestheticMedNum int(3) NOT NULL auto_increment,
                                    IntakeDate datetime NOT NULL,
                                    AnestheticMed char (20) NOT NULL,
                                    DEASchedule char(2),
                                    Qty int(6) NOT NULL,
                                    SupplierIDNum char(11) NOT NULL,
                                    InvoiceNum char(20) NOT NULL,
                                    PRIMARY KEY (AnestheticMedNum)
                                    ) DEFAULT CHARSET=utf8";
                    General.NonQ(command);

What would the proper command later on if I want to add a new field to this table?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but it appears that C# doesn't allow the changing of a table structure as from this forum...so you would have to probably alter from your stored procedure
but it appears that C# doesn't allow the changing of a table structure as from this forum...so you would have to probably alter from your stored procedure based on the number of Field Parameters...i.e. use something like in stored procedure like if columns less than the parameter string list that passed in, alter table to include new field name(s)...

http://forums.devshed.com/net-development-87/altering-a-table-in-c-176955.html
Avatar of wjstarck
wjstarck

ASKER

OK, NVM I found it. This works:

      string[] commands = new string[]
                        {
                              "ALTER table userod ADD AnesthProvType int(2) NOT NULL"
                              
                        };
                    General.NonQ(commands);
                        }
I'll give partial points to silemone for pointing me in the right direction...
Thanks