I am trying to pass a datable from one form to another. Datable has been retrieve successfully from database but program is throwing a Null reference exception error when deploying on the device. My code for
form 1
:
if (comboBox1.SelectedItem.ToString() == "Select by Picture")
{
MySqlConnection con = new MySqlConnection("server=******;port= *****;database=********;User Id=root;Password=;");
MySqlDataAdapter d_a = new MySqlDataAdapter("Select Picture From sampledata", con);
DataTable d_t = new DataTable();
d_a.Fill(d_t);
int count = d_t.Rows.Count;
PictureSelection ps = new PictureSelection();
if (count > 0)
ps.Storelist.Items.Clear();
for (int i=0 ; i <count; i++)
{
ps.Storelist.Items.Add(d_t.Rows[i][0].ToString());
}
ps.ShowDialog();
}
else if (comboBox1.SelectedItem.ToString() == "Select by Artist Name")
{
MySqlConnection con = new MySqlConnection("server=*****;port= ****;database=*****;User Id=root;Password=;");
MySqlDataAdapter d_a = new MySqlDataAdapter("Select Artist Name From sampledata", con);
DataTable d_t = new DataTable();
d_a.Fill(d_t);
int count = d_t.Rows.Count;
PictureSelection ps = new PictureSelection();
if (count > 0)
ps.Storelist.Items.Clear();
for (int i = 0; i < count; i++)
{
ps.Storelist.Items.Add(d_t.Rows[i][0].ToString());
}
ps.ShowDialog();
}
}
Form2
:
private void PictureSelection_Load(object sender, EventArgs e)
{
Storelist.DataSource = mainmn.d_t;
}
Any help will be appreciated.