jrpaarlberg 0 Newbie Poster

I was wondering if anyone could help me. I am working on a program in VS2008 with C# which has a datagridview populated from 2 SQL Express tables and needs to save to only 1 database.

Below is the code I have working so far:

public frmGrid()
        BindingSource bs = Program.dbman.GetData();
        dataGridView1.DataSource = bs;
        bindingNavigator1.BindingSource = bs;
        //Above code works.  need a binding source for the dgv AND bn to both connect to

        //Creates an event handler for editing a cell (event handle below)
        dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);

        //Makes the folowing columns read only
        dataGridView1.Columns["MixName"].ReadOnly = true;
        dataGridView1.Columns["MixId"].ReadOnly = true;

        //Rexizes specific columns
        dataGridView1.Columns["flcId"].Width = 50;
        dataGridView1.Columns["MixId"].Width = 50;
        dataGridView1.Columns["BatchNo"].Width = 50;

        //Adds filter for columns (remeber to add using statement)
        foreach (DataGridViewColumn col in dataGridView1.Columns)
            col.HeaderCell = new


The code that selects my data for the datagridview is here:

  public BindingSource GetData()
        string strSQL = "SELECT tblMix.MixName, tblCrushDatasheet.flcId, tblCrushDatasheet.MixId, tblCrushDatasheet.BatchNo, tblCrushDatasheet.Sizing, tblCrushDataSheet.KilnPosition, tblCrushDatasheet.tmpTempF, tblCrushDatasheet.FiringTemp, tblCrushDatasheet.FiringProfile, tblCrushDatasheet.FiringConditions, tblCrushDatasheet.FiredColor, tblCrushDatasheet.NoOfCrucibles, tblCrushDatasheet.ScreenedMethd, tblCrushDatasheet.ScreenedDate, tblCrushDatasheet.ScreenedTech, tblCrushDatasheet.SampleVolume, tblCrushDatasheet.SampleWeight, tblCrushDatasheet.LFDFunnelNo, tblCrushDatasheet.LFD1Tech, tblCrushDatasheet.LFD1Date, tblCrushDatasheet.LFD2Tech, tblCrushDatasheet.LDF2Date, tblCrushDatasheet.Plus40Weight, tblCrushDatasheet.PanWeight, tblCrushDatasheet.CrushScreenSet, tblCrushDatasheet.LbfFinal, tblCrushDatasheet.LbfMax, tblCrushDatasheet.PressureProfile, tblCrushDatasheet.CrushCellNo, tblCrushDatasheet.CrushTech, tblCrushDatasheet.CrushScreenTech, tblCrushDatasheet.FiredDate, tblCrushDatasheet.CrushDate, tblCrushDatasheet.DataSheetNo, tblCrushDatasheet.tmpTorF, tblCrushDatasheet.tmpCrushNo, tblCrushDatasheet.Notes, tblCrushDatasheet.Locked, tblCrushDatasheet.LockedBy, tblCrushDatasheet.ModUser, tblCrushDatasheet.ModDate FROM " + "tblMix LEFT JOIN tblCrushDatasheet ON " + "tblMix.MixId = tblCrushDatasheet.MixId";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strConnString);
            SqlCommandBuilder commandbuilder = new SqlCommandBuilder(dataAdapter);

            System.Data.DataTable table = new System.Data.DataTable();
            BindingSource dbBindSource = new BindingSource();
            dbBindSource.DataSource = table;

            return dbBindSource;
        catch (Exception e)
            return null;

I am trying to configure a Save button on the form that will send all changes made on the datagridview to the database and have not found a solution that either works, or that I understand.

Any help would be greatly appreciated.

PS - I thought this would be the easiest part, but for me it clearly is not.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.