从数据库取值到文本框 [英] Fetching value from Database to textbox
问题描述
嗨
你能纠正我哪里出问题了吗?
从数据库中,我正在将值检索到文本框.
Hi
Could you pls correct me where i am going wrong.
From database i am retriving the value to textbox.
SqlDataReader reader = null;
string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
string sqlcommand = "SELECT DoNo from DO where DoNo = DoNo";
SqlCommand cmd = new SqlCommand(sqlcommand, conn);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
dono = reader["DoNo"].ToString();
dono = DoNotb.Text;
}
我可以在这里看到值
i am able to see the value here
{
dono = reader["DoNo"].ToString();
dono = DoNotb.Text;
}
终于变成空了
问候
Lancy
finally it is becoming null
Regards
Lancy
推荐答案
while (reader.Read())
{
dono = reader["DoNo"].ToString();
DoNotb.Text = dono;
}
我假设DoNotb
是您的TextBox
吗?在这种情况下,您的最后一行代码应该转过来:
I assumeDoNotb
is yourTextBox
? In that case your last line of code should be turned around:
dono = reader["DoNo"].ToString();
DoNotb.Text = dono;
当前,您正在为dono
变量提供TextBox
的值,该值为空.
相反,应该像我的代码中那样,为TextBox.Text
赋予dono
变量的值.
请注意,在每个新迭代中,您的TextBox
中的Text
都会被覆盖.这样一来,您总会得到数据库中最后一行的值.
You are currently giving the dono
variable the value of your TextBox
, which is empty.
Instead you should give your TextBox.Text
the value of the dono
variable, as in my code.
Do notice that the Text
in your TextBox
is overridden in every new iteration. So you will always end up with the value of the last row in your database.
分配是错误的.
您已将文本框"值分配给变量.完全相反.
Assignment is wrong.
you have assign Textbox value to variable. do exactly reverse.
DoNotb.Text = dono;
这篇关于从数据库取值到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!