如何在sql数据库中保存和编辑多行文本框的值? [英] How to save and edit the value of a multiline textbox in sql database?

查看:112
本文介绍了如何在sql数据库中保存和编辑多行文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问题列中使用多行文本框。

我的代码是:

I am using a multiline textbox for the "Question" column.
My code is :

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 :(

推荐答案

只需使用Text属性:

Just use the Text property:
string s = myTextBox.Text;

并将数据库中的文本保存为普通字符串。

每个line将被\\\\ n终止。

当你从数据库重新加载它时,只需直接设置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.


您的INSERT语句需要5个参数值,但您只传递其中的4个参数值。纠正它,它应该工作。您还应提前捕获文本并检查其有效性,而不是仅仅假设您的用户将输入正确的信息。
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.


这篇关于如何在sql数据库中保存和编辑多行文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆