如何从具有多个值的单列的数据库中填充texbox? [英] How to fill a texbox from database having single column with multiple values?

查看:54
本文介绍了如何从具有多个值的单列的数据库中填充texbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好......

i在mysql中创建了一个数据库,其中单个coloumn有多个值...

例如... coloumn名字'HOD',有各个部门的HOD'列表......

所有这些值必须填写在一个文本框中。



有谁知道如何这样做不使用javascript吗?



我尝试过:



Hello...
i have created one database in mysql where single coloumn having multiple values...
for example... coloumn having name 'HOD',has list of HOD'S FROM various department...
all this value has to be filled in a single textbox.

Does anyone know how to do this without using javascript?

What I have tried:

string sql = "select HOD,IS_HOD_APPROVED from ch_hod where REQ_RECORD_ID= '" + vals + "'";
command.CommandText = sql;
OracleDataReader reader = command.ExecuteReader();
reader.FetchSize = reader.RowSize * 1000;
while (reader.Read())
{

    Session["Emp_hd"] = reader["HOD"].ToString();
}
lbl_name.Text = Session["Emp_hd"].ToString();





i在c#代码上方使用...

但这只会获取最后一个值.. ..



i used above code in c#...
but this will fetch only last value....

推荐答案

正如@NotPoliticallyCorrect指出的那样,你所做的就是不断覆盖以前的值。

如果你想要一个清单然后考虑使用除TextBox之外的适当控件。例如。 ListBox或DataGrid。在这里,我假设您有一个名为 lbl_name 的多行文本框,但通过使用参数化查询减轻了SQL注入风险。 (注意这是未经测试的)

As @NotPoliticallyCorrect has pointed out, all you are doing is continuously overwriting the previous value.
If you want a list of values then consider using an appropriate control other than a TextBox. E.g. a ListBox or DataGrid. Here I have assumed you have a multiline text box called lbl_name however and have mitigated the SQL Injection risk by using a parameterised query. (note this is untested)
string sql = "select HOD,IS_HOD_APPROVED from ch_hod where REQ_RECORD_ID= @vals";
command.CommandText = sql;
command.Parameters.AddWithValue("@vals",vals);
OracleDataReader reader = command.ExecuteReader();
reader.FetchSize = reader.RowSize * 1000;
StringBuilder sb = new StringBuilder("");
while (reader.Read())
{
    sb.Append(reader["HOD"].ToString());
    sb.Append(Environment.NewLine);

}
Session["Emp_hd"] = sb.ToString();
lbl_name.Text = sb.ToString();


这篇关于如何从具有多个值的单列的数据库中填充texbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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