将数据从SQL DB表显示到文本框 [英] Displaying data from SQL DB table into Textbox
本文介绍了将数据从SQL DB表显示到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是asp.net的新手.而且不喜欢它
到目前为止.
我需要从DropDownList中选择一个项目
(与数据源链接到SQL表的数据)和
将同一表中的信息填充到文本框中.
请提供任何帮助!
Hi,
I am new with asp.net. And not enjoying it so
so far.
I need to choose an item from the DropDownList
(Data linked with Data Source to SQL Table) and
populate info from same table into a textbox.
Please any help would be appriciated!!
推荐答案
AutoPostBack="True" OnSelectedIndexChanged="droplist1_SelectedIndexChanged"
protected void droplist1_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(conn))
{
string query = "select * from Login where uname='" + droplist1.SelectedValue + "' ";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
txtbox1.Text=ds.Tables[0].Rows[0].ItemArray[0].ToString();
}
}
}
您应在dropdownlist selectedindexchanged事件
上编写以下代码
you should write the following code on dropdownlist selectedindexchanged event
dim str as string
str="select column from tablename where colname=@condition"
dim con as new SqlConnection("Data Source=.;Initial Catalog=master; uid=sa;pwd=12335")
dim cmd as new SqlCommand(str,con)
cmd.CommandType=CommandType.Text
cmd.Paramaters.AddWithValue("@condition",DropDownList1.SelectedValue)
dim adap as new SqlDataAdapter(cmd)
dim dt as new DataTable
adap.fill(dt)
TextBox1.text=dt.Rows(0)(0).ToString()
DataSet dtst_Equals = ObjCommon.GetObject.ExecuteQuery_Select(Connection.ConnectionString,从Tbl_Property_Master中选择Created_By,其中Record_Id =""+ ID +"");
如果(dtst_Equals.Tables [0] .Rows.Count!= 0)
{
drplst_Country.SelectedValue = dtst_get_details.Tables [0] .Rows [0 ["Country"].ToString();
}
DataSet dtst_Equals = ObjCommon.GetObject.ExecuteQuery_Select(Connection.ConnectionString, "select Created_By from Tbl_Property_Master where Record_Id=''" + Id + "''");
if (dtst_Equals.Tables[0].Rows.Count != 0)
{
drplst_Country.SelectedValue = dtst_get_details.Tables[0].Rows[0["Country"].ToString();
}
这篇关于将数据从SQL DB表显示到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文