Im having some problems parsing a string to a textbox type, im using the code in a diffrent form in the program and its working fine, but when im tying the same two lines here i get a null exception
the two lines of intrest is
string txbName = "br" + bruker + "txt" + 'B' + o;
txtBCont = (TextBox)Controls[txbName];
new info
Greg put me in the direction to check waht was inside the Controls[] array and this reveals what my problem is. It only contains 90 lines of TabControl info.
this is the line
System.Windows.Forms.TabControl, TabPages.Count: 2, TabPages[0]: TabPage: {ShowWeek}
this line is dublicated 90 times when i run this code inside my catch block
catch( System.Exception excep)
{
System.IO.StreamWriter SW;
SW = File.AppendText("C:\\MyDumpFile.txt");
foreach (Control ctrl in Controls)
{
SW.WriteLine(ctrl);
}
SW.Close();
}
how can this be isen't the Controls array populated on Initialize?
Orginal post
and this is the full loop
int dayOfset;
int bruker;
TextBox txtBCont;
for (int i = 0; i < 18; i++)
{
mysqlCon.Open();
dayOfset = -4;
bruker = i + 1;
for (int o = 1; o < 6; o++)
{
MySqlCommand cmd = new MySqlCommand("SELECT (NyeSaker + GamleSaker - (select GamleSaker FROM saker Where Dato = '" + dateTimePicker1.Value.AddDays(dayOfset + 1).ToString("yyyy-MM-dd") + "' AND Bruker_ID = '" + bruker + "' ) ) FROM saker Where Bruker_ID = '" + bruker + "' AND Dato = '" + dateTimePicker1.Value.AddDays(dayOfset).ToString("yyyy-MM-dd") + "'", mysqlCon);
string txbName = "br" + bruker + "txt" + 'B' + o;
txtBCont = (TextBox)Controls[txbName];
//1 past og dp kontrol//
try
{
txtBCont.Text = cmd.ExecuteScalar().ToString();
}
catch( System.Exception excep)
{
//txtBCont1.Text = "0";
MessageBox.Show(excep.Message);
}
dayOfset++;
}
mysqlCon.Close();
}
in trying to debug it i did this
string txbName = "br" + bruker + "txt" + 'B' + o;
txtBCont = br1txtB1;
txtBCont = (TextBox)Controls[txbName];
and what happens is it sets the txtBCont to Textbox on this line txtBCont = br1txtB1; but on the txtBCont = (TextBox)Controls[txbName]; it sets it back to null again.
anyone got a clue what the error is here?