3 Replies - 1290 Views - Last Post: 07 September 2010 - 12:49 PM

#1 jagman82  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 24-February 10

MySQL multiple entries for ONE row in a table

Posted 07 September 2010 - 06:30 AM

I am needing to insert multiple entries within the same row. First, would this be an insert command or update command to the row? Also, when I do use the insert statement, it goes in the proper column but adds a new row every time. Any help is appreciated.

string [] columnnames = { "Key_Backup_Entry", "FinEff_Backup_Entry", "Cast_backup_Entry",
"Guest_Backup_Entry", "Ops_Backup_Entry", "Context_Backup_Entry",
"Other_Backup_Entry" };


  Int32 column = Convert.ToInt32(ddlCategories.SelectedValue);


String query = "INSERT INTO donald_notebook.notebook(" + columnnames[column] + ",WE_Date) " +
"VALUES(@text, @WE_Date)";

           
 DatabaseDAL databaseDal = new DatabaseDAL();

            databaseDal.createCommand(query);
            databaseDal.addParameter("@text", txt1.Text, DbType.String);
            databaseDal.addParameter("@WE_Date", txtDate.Text, DbType.DateTime);


            databaseDal.insert();



MOD EDIT: Proper code tag usage:

:code:

This post has been edited by JackOfAllTrades: 07 September 2010 - 07:31 AM
Reason for edit:: Fixed code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: MySQL multiple entries for ONE row in a table

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,369
  • Joined: 12-June 08

Re: MySQL multiple entries for ONE row in a table

Posted 07 September 2010 - 09:16 AM

View Postjagman82, on 07 September 2010 - 07:30 AM, said:

I am needing to insert multiple entries within the same row. First, would this be an insert command or update command to the row? Also, when I do use the insert statement, it goes in the proper column but adds a new row every time. Any help is appreciated.

string [] columnnames = { "Key_Backup_Entry", "FinEff_Backup_Entry", "Cast_backup_Entry",
"Guest_Backup_Entry", "Ops_Backup_Entry", "Context_Backup_Entry",
"Other_Backup_Entry" };


  Int32 column = Convert.ToInt32(ddlCategories.SelectedValue);


String query = "INSERT INTO donald_notebook.notebook(" + columnnames[column] + ",WE_Date) " +
"VALUES(@text, @WE_Date)";

           
 DatabaseDAL databaseDal = new DatabaseDAL();

            databaseDal.createCommand(query);
            databaseDal.addParameter("@text", txt1.Text, DbType.String);
            databaseDal.addParameter("@WE_Date", txtDate.Text, DbType.DateTime);


            databaseDal.insert();



MOD EDIT: Proper code tag usage:

:code:

You are confusing what insert and update mean. You *insert* to make a new row in the table... you *update* to alter the columns of data for a given set of rows that already exist in the table.

When you say "I am needing to insert multiple entries within the same row." are you talking about creating more columns for the table on the fly? That's a really bad design process.

If you mean for a given, and existing, row in a table you need to update specific cells on it? Yeah that's an update.
Was This Post Helpful? 0
  • +
  • -

#3 jagman82  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 24-February 10

Re: MySQL multiple entries for ONE row in a table

Posted 07 September 2010 - 12:15 PM

With my update statement, how am I sure that the right row is being called? From my code, you can see that I have 7 drop down list that need to be tied to one entry and not multiple rows of entries.

jagman
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: MySQL multiple entries for ONE row in a table

Posted 07 September 2010 - 12:49 PM

You must call update with a WHERE clause so that you can be sure you are updating the correct row.

UPDATE [table] SET [colname]=[colvalue], [colname2]=[col2value] WHERE [identifying_column]=[the_id_to_update]

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1