I'm not sure why you use the TextBox.TextChanged event. Shouldn't you use the
ListControl.SelectedIndexChanged Event (System.Web.UI.WebControls)[
^]?
And as Richard Deeming said in the comment, use a parameterized query instead.
private string connectionString = ???;
void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > -1)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("SELECT Salary FROM Employees WHERE Empname = @empName", conn);
cmd.Parameters.AddWithValue("@empName", DropDownList1.SelectedValue.ToString());
conn.Open();
int value = (int)cmd.ExecuteScalar();
TextBox1.Text = value.ToString();
}
}
}