简体   繁体   中英

Data From Database display to textbox c#

Good day Guys. I want to display the value of Townhouse into txthouse after selecting code from the data Thank you guys .

DataTable dtRefItem = Common.Common.GetData("SELECT Townhouse FROM County where code= '"+txtbox.text"'"

I would recommend using sql parameters instead of building up the sql command with just strings. this will help limit your exposure to sql injection and is just a good practice to start.

A DataTable normally contains multiple DataRow s. Even if you select only one you need to access that row from it's DataTable.Rows -property .

string townHouse = null;
if(dtRefItem.Rows.Count > 0)
{
    townhouse = dtRefItem.Rows[0].Field<string>("Townhouse");
}
txthouse.Text = townHouse;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM