Connect multiple textbox to the database in WinApp

Fuhans

New member
Joined
Jul 27, 2013
Messages
1
Programming Experience
Beginner
Here is my case:
I have created 2 form which is login form, which username textbox already connected to the database and it is successfully.
When user login, it direct to the second form, and in the second form, there are multiple textbox that i have created using Array List, and it has shown.


Here is my problem:
I want to connect the textboxes in second form to the database, but it shown nothing when i run the program, i already trace the code which is the error, and the error is on when OleDBDataReader is reading, i dunno what's wrong with my code, in login form it run perfectly, but in the second form, there is an error.

Here is the image for Login Form:
Capture.PNG


Here is the image for Second Form:
Capture_2.PNG


Here is the code for Second Form:
C#:
      private List<List<TextBox>> textBoxCodeContainer = new List<List<TextBox>>();
 
string connectionString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\Archives\Projects\Program\Sell System\Sell System\App_Data\db1.accdb;Persist Security Info=False;");
 
//****TextBox for Code****
for (int y = 0; y <= 16; y++)
{
   textBoxCodeContainer.Add(new List<TextBox>());
   textBoxCodeContainer[0].Add(new TextBox());
   textBoxCodeContainer[0][y].Size = new Size(100, 50);
   textBoxCodeContainer[0][y].Location = new Point(25, 150 + (y * 25));
 
   Controls.Add(textBoxCodeContainer[0][y]);
}
 
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT DISTINCT [Code] FROM [Data] ORDER BY [Code] ASC", conn);
dReader = cmd.ExecuteReader();
AutoCompleteStringCollection codesCollection = new AutoCompleteStringCollection();
 
while (dReader.Read())
{
   codesCollection.Add(dReader.GetString(0));
}
 
textBoxCodeContainer[0][0].AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxCodeContainer[0][0].AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxCodeContainer[0][0].AutoCompleteCustomSource = codesCollection;
 
dReader.Close();
conn.Close();

For the Second Form, in the column of code, it supposed to shown the autocomplete like at the Login Form.

Thank you.
 
Top Bottom