Im trying to populate a text box with infromation that is searched by using a customerID which is inputted throught a text box here is the code im using below
private void txtCustomerID_TextChanged(object sender, EventArgs e)
{
string strCon = Properties.Settings.Default.PID2dbConnectionString;
OleDbConnection conn = new OleDbConnection(strCon);
String sqlPoints = "SELECT points FROM customer WHERE [customerID]=" + txtCustomerID.Text;
txtPoints.Text = sqlPoints;
}
but the text box “txtPoints” only outputs the text of the sqlpoints and not the information in the database? I’m not exactly sure what im doing wrong here.
Any help is appreciated, thanks in advance.
You are not executing the SQL statement on the database. Instead, you are assigning it to
txtPoints.Text. You need to execute it on the DB server using, e.g., an OleDbCommand object.What you need to do instead is something like the following (note this is pseudo-code – I haven’t tested it runs)
Note also my use of using. This will ensure that your database connections are properly closed once you are finished with them.