private void BindColumn() { try { for (int i = 0; i < dataGridView_tontai.Columns.Count; i++) { string strname = dataGridView_tontai.Columns[i].Name; dm_tonghopcol dm = SQLDatabase.Loaddm_tonghopcol(string.Format("select * from tonghopcol where cot='{0}'", strname)).FirstOrDefault(); if (dm != null && dm.ten.Length != 0) { dataGridView_tontai.Columns[i].HeaderText = dm.ten; } } for (int i = 0; i < dataGrid_ListTelNumberNew.Columns.Count; i++) { string strname = dataGrid_ListTelNumberNew.Columns[i].Name; dm_tonghopcol dm = SQLDatabase.Loaddm_tonghopcol(string.Format("select * from tonghopcol where cot='{0}'", strname)).FirstOrDefault(); if (dm != null && dm.ten.Length != 0) { dataGrid_ListTelNumberNew.Columns[i].HeaderText = dm.ten; } } } catch (Exception) { throw; } }
private void button1_Click(object sender, EventArgs e) { try { StorePhone.SQLDatabase.ExcDataTable("DBCC CHECKIDENT ('[tonghopcol]', RESEED, 0); delete from tonghopcol"); foreach (DataGridViewRow row in dataGridView1.Rows) { dm_tonghopcol dm = new dm_tonghopcol(); dm.id = ConvertType.ToInt(row.Cells["id"].Value); dm.ten = row.Cells["ten"].Value.ToString(); dm.cot = row.Cells["cot"].Value.ToString(); SQLDatabase.Adddm_tonghopcol(dm); //dataGridView1.CurrentCell = dataGridView1.Rows[row.Index].rows[0]; } BindData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "button1_Click"); } }