I'm trying to figure out what is going on with my code and I can't figure it out. I'm trying to query a db to find out information where a user previously selected a variable.
The problem I'm running into is that it never replaces the @client with the value in the Parameters.AddWithValue method. I'm just not sure what I'm doing wrong.
selClient = comboBox1.SelectedItem.ToString();
string cmdText = "Select [Tax EIN] From [TblClientInfo] Where [Client Name] = '@client';";
using (var conn = new SqlConnection("connection info"))
{
SqlCommand cmd2 = new SqlCommand(cmdText, conn);
{
cmd2.Parameters.AddWithValue("@client", selClient);
try
{
conn.Open();
SqlDataReader rd = cmd2.ExecuteReader();
while (rd.Read())
{
MessageBox.Show(String.Format("{0}", rd[0]));
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
}
Please ignore all of the generic variables, I'm new to programming and am trying to do this all as a test run before I actually make a usable program.