如何在文本框中显示数据 [英] How Can I Display The Data In Textbox
本文介绍了如何在文本框中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法填写网格视图,但是
I managed to fill the grid view but
protected void btnShow_Click(object sender, EventArgs e)
{
string conStr = ConfigurationManager.ConnectionStrings["CStringCRM"].ToString();
DataTable dt = new DataTable();
SqlDataReader dr = null;
using (SqlConnection conn = new SqlConnection(conStr))
{
// Creating insert statement
string sql = string.Format(@"SELECT * FROM UserInfo");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
dr = cmd.ExecuteReader();
dt.Load(dr);
conn.Close();
cmd = null;
}
GView.DataSource = dt;
GView.DataBind();
txtFName.Text = dr["UFName"].ToString();
}
我还想在文本框中显示 txtFName的数据
但这些代码不起作用 txtFName.Text = dr [UFName]。ToString();
。
请帮助
I also want to display the data in textbox which are txtFName
but these code does not working txtFName.Text = dr["UFName"].ToString();
.
Please help
推荐答案
Hi
使用断点并检入dt,在该数据表中获得UFName值?
和你正在使用
Hi Use break point and check in dt,in that datatable got UFName value ?
and u are using
Select * from table name
中选择* 以便你检索很多记录,然后你需要指定哪一行。
so in that u retrieve lot of records,then u need to specify which row.
dt.Rows[0]["UFName"].ToString();
这篇关于如何在文本框中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文