narasiman rao

narasiman rao

  • NA
  • 519
  • 771.6k

save the data grid view data in to data base.

Jan 12 2013 12:14 AM
Database as follows;

 Date         datetime
 Session      int
 Course       varchar(20)
Faculty_ Code varchar(20)


 but i want save the data grid view data in to the data base.

private void BtnSave_Click(object sender, EventArgs e)
        {
            Save Details();
        }


 private void SaveDetails()
        {
            try
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("date", typeof(string));
                dt.Columns.Add("sess", typeof(int));
                dt.Columns.Add("crs", typeof(string));
                dt.Columns.Add("Fac", typeof(string));
                for (int i = 0; i < datagridView.RowCount; i++)
                {
                    for (int j = 2; j < datagridView.ColumnCount; j++)
                    {
                        if (datagridView[j, i].Value != null)
                  
                        {
dt.Rows.Add(datagridView[0, i].Value.ToString(), datagridView[1, i].Value.ToString(), datagridView[j, i].Value.ToString(), datagridView.Columns[j].HeaderText.ToString());
                        }
                    }
                }
                dataGridView1.DataSource = dt;
            }
            catch (Exception Ex1)
            {
                MessageBox.Show(Ex1.ToString(), "Error", MessageBoxButtons.OK);
            }
        }


i save the data grid view data into the another data grid view data using data table.

i want to save the data grid view data in to the data base.

how to do.please help me.

Answers (3)