0

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"'"
7
  • What Common.Common.GetData exactly do? And looks like you need to use + after txtbox.text like '" + txtbox.text + "'" Commented Apr 10, 2014 at 6:39
  • Good. What's the question and what have you tried? Commented Apr 10, 2014 at 6:39
  • @SonerGönül get the data from the database. I use already that sir i encounter error. Commented Apr 10, 2014 at 6:42
  • @ThorstenDittmar I need to display the value of townhouse when I select the value of code . Commented Apr 10, 2014 at 6:43
  • @renats I get what you want, but you're not asking a specific question - but could you please explain what your problem is/what error you're getting/what's not working/what you've tried. Just anything that makes this a question which will not be closed for "unclear what you're asking"... Commented Apr 10, 2014 at 6:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

A DataTable normally contains multiple DataRows. 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;

1 Comment

Thank you sir for the effort ^^ @TimSchmelter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.