Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using a multiline textbox for the "Question" column.
My code is :
C#
cmd.CommandText = string.Format(@"INSERT INTO tblTrueOrFalse ([QuizNo], [QuesNo], [Question], [Answer]) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')",
                           txtQuizNo.Text.Trim(),
                           txtQuesNo.Text.Trim(),
                           txtTFQues.Text.Trim(),
                           cboxTFAns.Text.Trim());


I don't know how to save the texts from the multiline textbox :( its my first time to use a multiline textbox. Please help me :(

What I have tried:

I didn't tried anything yet because i don't have any idea on how to do it :(
Posted
Updated 6-Mar-16 4:40am
v3
Comments
Sascha Lefèvre 6-Mar-16 10:01am    
Why do you think it would be any different from a single line textbox? The database doesn't care if there are line breaks in the text.
Hikari18 6-Mar-16 10:06am    
there's an error whenever i try to add or edit it
Sascha Lefèvre 6-Mar-16 10:14am    
When you ask for help with an error you should tell the exact error message ;-)

Just use the Text property:
C#
string s = myTextBox.Text;
And save the text in your DB as a normal string.
Each line will be terminated by "\r\n".
When you reload it from your DB, just set the Text property directly, and the lines will sort themselves out.
 
Share this answer
 
Comments
Hikari18 6-Mar-16 10:13am    
sorry, but i don't get it. i tried the code you've given but its still the same. https://www.dropbox.com/s/i6i8trzrxctxqhs/Capture.PNG?dl=0 -- here's the printscreen of the error.
OriginalGriff 6-Mar-16 10:26am    
That error message has nothing at all to do with multiline textboxes.
It's to do with a StringBuilder, and you doing something odd with it.
So use the debugger, and find out what is going on, and exactly where. And don't post screenshots of error messages - copy and paste the error text instead.
Hikari18 6-Mar-16 10:31am    
thank you i didn't notice that. i can't copy the error message, it can't be selected. too sleepy =__=
Your INSERT statement is expecting 5 parameter values, but you are only passing four of them. Correct that and it should work. You should also capture your text in advance and check it for validity, rather than just assuming your user will enter the correct information.
 
Share this answer
 
Comments
Hikari18 6-Mar-16 10:30am    
thanks sorry i didn't notice that. Im too sleepy but i need to finish my project :( thank you very much
Richard MacCutchan 6-Mar-16 10:33am    
Is there some reason why everyone from the Philippines writes "I didn't tried anything yet because i don't have any idea on how do it" in the "What I have tried" section? Or is it just that you are using multiple identities to post lots of questions?
Hikari18 6-Mar-16 10:36am    
i don't have any idea. This is only my second post, don't be too judgemental lol

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