Solved

Help adding a field to MySQL table in C#

Posted on 2008-10-23
5
296 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
Comment Utility
alter the table...
0
 
LVL 21

Expert Comment

by:silemone
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

14 Experts available now in Live!

Get 1:1 Help Now