Question
· Dec 10, 2017

Cache and Database

Hi, I'm a student, weak programming. I ask for your help, I write a program in C #, there are two tables, but I do not understand how to organize the connection between them many to many. Table in DataGridView1 from DataSet1 on Form1 key connection in DataGridView1 from DataSet1 to Form3

I do this on Form1

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
{
  if (e.RowIndex >= 0)
  {
    DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
    Form1.IDfor3form = row.Cells[1].Value.ToString(); // By the Bilet column
    Form3 c = new Form3();
    c.Owner = this;
    c.Show();
  ​}
}

and on Form3

private void Form3_Load(object sender, EventArgs e)
​string select = "select  ID ,Bilet, NumberBook, Books, Daten, Daysn, Quantity, Surname from Human.PersonalBook WHERE Bilet = ('" + Form1.IDfor3form + "')";
string insert = "insert into Human.PersonalBook (Bilet, NumberBook, Books, Daten, Daysn, Quantity, Surname) values (?, ?, ?, ?, ?, ?,?)";
string update = "update Human.PersonalBook set  Bilet = ?, NumberBook = ?, Books = ?, Daten = ?, Daysn = ?,  Quantity = ?, Surname = ? where  ID= ?";
string delete = "delete from Human.PersonalBook where ID = ?";
conAdapter = new CacheDataAdapter(select, CacheConnect);
conAdapter.UpdateCommand = CacheConnect.CreateCommand();
conAdapter.UpdateCommand.CommandText = update;
AddParams(conAdapter.UpdateCommand, "Bilet", "NumberBook", "Books", "Daten", "Daysn", "Quantity", "Surname", "ID");
conAdapter.InsertCommand = CacheConnect.CreateCommand();
conAdapter.InsertCommand.CommandText = insert;
AddParams(conAdapter.InsertCommand, "Bilet", "NumberBook", "Books", "Daten", "Daysn", "Quantity", "Surname");
conAdapter.DeleteCommand = CacheConnect.CreateCommand();
conAdapter.DeleteCommand.CommandText = delete;
AddParams(conAdapter.DeleteCommand, "ID");
conAdapter.Fill(dataSet1, "Books");
Discussion (1)0
Log in or sign up to continue