I have a drop down list on one form that populates a puzzle id code from a sql table.
when the user selects a puzzle code say “puzzle2” i want the next form(play:Form) to display this puzzle. At the moment i can only get it to display the 1st puzzle “puzzle1” on the page.
The database consists of puzzleID which is the puzzle type and puzzle which is the puzzle question itself.
public partial class Play : Form
{
public Play()
{
InitializeComponent();
SqlConnection conn = new SqlConnection("Data Source=LAURA-PC;Initial Catalog=Sudoku;Integrated Security=True");
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "Select puzzle from Puzzle";
command.CommandType = CommandType.Text;
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
string[] tokens = ((string)reader[0]).Split(';');
textBox1.Text = tokens[0];
textBox2.Text = tokens[1];
textBox3.Text = tokens[2];
textBox4.Text = tokens[3];
textBox5.Text = tokens[4];
textBox6.Text = tokens[5];
textBox7.Text = tokens[6];
textBox8.Text = tokens[7];
textBox9.Text = tokens[8];
textBox10.Text = tokens[9];
textBox11.Text = tokens[10];
textBox12.Text = tokens[11];
textBox13.Text = tokens[12];
textBox14.Text = tokens[13];
textBox15.Text = tokens[14];
textBox16.Text = tokens[15];
}
conn.Close();
}
I know i need to implement some sort of of global variable from the drop down list in the previous form and then try filter that variable into Where statement? But im having no luck.
Thanks
You can make an static class as a common place to share objects. All classes can see this class and use its members.
Also you can have a property on the second form to accept the puzzle id. Like this :