Help adding a field to MySQL table in C#

Posted on 2008-10-23
Last Modified: 2013-12-17

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("")) {
                        string command;
                        if(DataConnection.DBtype==DatabaseType.MySql) {

                    command = "DROP TABLE IF EXISTS anesthmedsintake";
                    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";

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

Question by:wjstarck
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 21

Accepted Solution

silemone earned 500 total points
ID: 22787220
alter the table...
LVL 21

Expert Comment

ID: 22787243
but it appears that C# doesn't allow the changing of a table structure as from this you would have to probably alter from your stored procedure
LVL 21

Expert Comment

ID: 22787279
but it appears that C# doesn't allow the changing of a table structure as from this 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)...

Author Comment

ID: 22788529
OK, NVM I found it. This works:

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

Author Closing Comment

ID: 31509260

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question