I'm a newbie from C# and I'm currently using C# vs 2013 and MS access database..I'm trying to do the mulitple inserts and at the same time trying to attempt foreach.. I have 2 tables in access
first table
EID ------ FirstName
10175-- random names
10176-- random names
10177-- random names
10178 --random names
10179 --random names
10180 --random names
2nd table
index--- EID-----Date(index is autonumber type)
1-------10175----10/10/2014
2-------10175----10/11/2014
3-------10175----10/12/2014
4-------10175----10/13/2014
5-------10175----10/14/2014
6-------10175----10/15/2014
7-------10175----10/16/2014
8-------10175----10/17/2014
9-------10175----10/18/2014
10------10175----10/10/2014
what I wanted to happen was when I click a button I want to insert 10 record dates on 2nd table FOR EACH EID on the first table..here's my code for the loop 10 records for 10175
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
int ctr = 0;
int counter;
counter = int.Parse(TimeIntxt.Text);//I just use textbox for test i want this to be autogenerate based on the number of EID on first table
String counter2;
for (ctr = 0; ctr < 10; ctr++)
{
counter++;
counter2 = dateTimePicker1.Value.AddDays(ctr + 1).ToString();
command10.CommandText = "insert into EmployeeData (EID,DateIn) values('" + counter + "','" + counter2 + "')";
command10.ExecuteNonQuery();
}
MessageBox.Show("successfully created");
connection.Close();
Very much thankful for those who will help me..I'm sorry if my english is not really fluent Y.Y
OleDbDataReaderto loop through the rows in the first table. See the related question here for an example.