Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day to all i'm using C# and mysql version 1.1.4. i hope someone can help me on how to add multiple data into TOname and nameTO i don't know what to do after so many trials. here are may code.



Query = "Insert into tblrightofwayagreement(Name,PS,PS1,brgy,mun,nameTO,TOnum,dateofack)" + "values('" + txtname.Text + "','" + cmbps.Text + "','" + txtps.Text + "','" + txtbrgy.Text + "','" + txtmun.Text + "','" + txtto.Text + "','" + txtpiece.Text +"','" + txtack.Text + "')";
Posted
Comments
syed shanu 5-Dec-14 0:26am    
What do you mean of multiple data in to specific column.do you want to store many values in one column for example TOname.text="toname1,toname2,toname3" like this.add more details to your question with example data and what input you want to give and what output you are expecting.

1 solution

If you want to add values from multiple textboxes into single column then you just concatenate the string...below is the example, you add the values you actually need.

Note the use of String.Format which enables you easy reading of the query without having to worry about closing all the quotes and easier copying into the database for testing. Note also that proper casing makes the thing more readable. Also, use full text instead of shortcuts like "brgy", you'll thank yourself in a year when you return and have no idea what that means :)

The answer to your question is bold, the rest is free education.
Query = String.Format("INSERT INTO tblRightOfWayAgreement (Name, PS, PS1, brgy, mun, nameTO, TOnum, dateoffack)
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', txtName.Text, cmbps.Text + " some other value",
txtPS.Text,
txtBrgy.Text,
txtMun.Text,
txtTO.Text,
txtPiece.Text,
txtAck.Text
)



Now that the solution is done:
I STRONGLY SUGGEST you use stored procedure or at least do something to prevent SQL Injection[^]
Consider what would happen if I entered the following in txtName
'; GO; DROP TABLE tblRightOfWayAgreement; --

NEVER TRUST USER INPUT!!

If this helps please take time to accept the solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900