Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have a table that have 2 columns (category and activity) i want to creat a c# form
that will insert rows data into the table. that is under category you can insert "Beautician" and the activity will be "barber, hair dresser, manicure"

i just dont know how to start. pls help me out
Posted
Comments
[no name] 26-Jun-12 14:30pm    
How to start what? How to start Visual Studio? How to start a project? How to create a form? How to create a database?
"pls" help us help you

1 solution

The actual SQL part of this would work via a UNION ALL operator between each line to be inserted in the one statement like so:

SQL
INSERT INTO myTable(category, activity)
SELECT 'Beautician', 'barber'
UNION ALL
SELECT 'Beautician', 'hair dresser'
UNION ALL
SELECT 'Beautician', 'manicure'


You would just need to build this statement in your C# code and then call it once against the database. This particular statement would insert three rows into the myTable table.
 
Share this answer
 
Comments
mikeoabban 26-Jun-12 16:34pm    
thanks alot it worked. but the problem is it takes it value from a textbox into
the db. when the textbox is empty it inserts an empty space inot the db. what can
i do to prevent this
Tim Corey 27-Jun-12 8:49am    
You should be doing validation on the data before you stick it into the database. Otherwise you could end up with serious issues (SQL injection, for example). On your textbox, check to be sure the data is valid before you add that line to the list. For example, check that the length is greater than zero. Also, run a RegEx against the string to be sure it doesn't contain any non-standard characters (whatever you define those as - best would be only letters and number be allowed but that depends on your business rules). That will fix your issue.
Tim Corey 27-Jun-12 11:54am    
It sounds like your question has been answered. If so, please mark the solution as accepted so that people who come across this question will know it has been solved. Otherwise, they may spend their time trying to help you when you no longer require assistance. Thanks.

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