Solved

Help adding a field to MySQL table in C#

Posted on 2008-10-23
5
297 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:wjstarck
  • 3
  • 2
5 Comments
 
LVL 21

Accepted Solution

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

Expert Comment

by:silemone
ID: 22787243
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
0
 
LVL 21

Expert Comment

by:silemone
ID: 22787279
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
0
 

Author Comment

by:wjstarck
ID: 22788529
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...
0
 

Author Closing Comment

by:wjstarck
ID: 31509260
Thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now