I have two forms, one form I enter information into that populates a db... on the other, I need to text on the buttons to change based on the information in the 'Description' field. This change should happen when I hit the save button on the other form. Here is my code:
Code:
private void ButtonTextChange()
{
SqlConnection conn = new SqlConnection("Data Source=DAHLENO0744\\;Initial Catalog=USPCNew;Integrated Security=True;Pooling=False");
try
{
conn.Open();
int myint = 1;
string sql = "select a.* from (SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 1";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 2";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 3";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 4";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 5";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 6";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 7";
sql += " union SELECT ButtonNum, Description FROM StationSetup WHERE ButtonNum = 8) as A order by ButtonNum";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
switch (myint)
{
case 1:
button_1_M.Text = reader[1].ToString();
button_1_C.Text = reader[1].ToString();
break;
case 2:
button_2_M.Text = reader[1].ToString();
button_2_C.Text = reader[1].ToString();
break;
case 3:
button_3_M.Text = reader[1].ToString();
button_3_C.Text = reader[1].ToString();
break;
case 4:
button_4_M.Text = reader[1].ToString();
button_4_C.Text = reader[1].ToString();
break;
case 5:
button_5_M.Text = reader[1].ToString();
button_5_C.Text = reader[1].ToString();
break;
case 6:
button_6_M.Text = reader[1].ToString();
button_6_C.Text = reader[1].ToString();
break;
case 7:
button_7_M.Text = reader[1].ToString();
button_7_C.Text = reader[1].ToString();
break;
case 8:
button_8_M.Text = reader[1].ToString();
button_8_C.Text = reader[1].ToString();
break;
}
myint++;
}
}
catch (Exception ex)
{
MessageBox.Show("There is an error" + ex);
}
finally
{
conn.Close();
}
}
What am I doing wrong?