Link to home
Start Free TrialLog in
Avatar of JasonWinn

asked on

Problem saving data


I have job entries, by row in sql, that are put there via dataset in C# program.

My goal is to have people check off things that are required for those job entries, like "estimated, po received, contract received" ect.

I was not sure if it was possible to work with checkboxes in sql so this was my plan:

When the user clicks on the DataGridView, the textboxes that are databound display the related data. (This works fine).

The user then has several checkboxes on the form. These checkboxes are databound to a textboxes on the form. These textboxes are storing/showing information from quickbooks:

estimateCheckbox - - - > estimateTextField.

The idea is that, when a user checks a checkbox, it changes the textbox and saves that information to sql. So when a user loads a job entry, the checkbox looks at the textbox, and based on the data in the textbox, the Checkbox is either True or False.

Simple right?

Here is the problem, when the user clicks a checkbox, the data in the textbox correctly changes to Y or N. The problem is, the data does not save.

However, if the user clicks the checkbox, the datachanges, then they click on a cell in the datagridview, it saves. Because I also have a save script for "onCellClick" in the datagridview.

Why does it not save when the user clicks save, but it saves when the user clicks Save and then a Cell?

Thanks, Here is the code for the OnCell event and the Save Button (SAVE button is what the user clicks after they make there selection on the checkbox).

        private void jobIntakeDataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
            if (estimate.Text == "Y")
                estimateBox.Checked = true;
                estimateBox.Checked = false;



        private void saveButton_Click(object sender, EventArgs e)
            if (estimateBox.Checked == true)
                estimate.Text = "Y";
                estimate.Text = "N";


Avatar of Gautham Janardhan
Gautham Janardhan

1.Is the check box in a column of the grid..
Avatar of JasonWinn


No the checkbox is a seperate control. The checkbox is basically the visible reference of whether the data in the grid or not.

Its weird, how if I click Save, it will not save, but if I click SaveButton, it will not save. But if I click saveButton, then change the selected cell, then click saveBUtton, it will save.

just to know if i got u right

Check boxes are separate and when they change a text in a text box also cahges automatically(this is not in grid)

the data contained in the grisd is  about job entries and u can also edit this right..

The checkbox changes the text in the TextBox. The textbox is databound to the datagridView/dataset. So If the user enables the checkbox, the text in the textbox becomes "Y". The problem is that the "Y" does not get saved to the datagridView/dataset unless the user selects a different cellRow in the datagrid.

if checkBox1.enable = true
    then textbox1.Text = "Y"
if checkbox1.enable = false
    then textbox1.Text = "N"

If the user hits "save", the Y or N does not get saved to the datagrid. If the user changes what row is selected in the datagridview, then hits saveButton, it works and saves the information.

Btw this is all going to SQL, its a dataGridView/DataSet/SQL scenario.


without trying to assign it to a text box why dont u try it assign directly to the dataset table cell..
this woudl be far more safer..

like u would have a key for the job entries row and u might be storing it when u dispaly details from the grid..

once a check is changed what u coudl do is

DataRow []ARow=  dataset.tables["urtable"].select(" keyfield = urvalue")

assuming this would return only one row
if checkBox1.enable = true
    then Arow[0]["URFIELD"] = "Y"
if checkbox1.enable = false
    then Arow[0]["URFIELD"] = "N"

That sounds like a far more safer way and I like it.

I am not using a dataGrid ( I think i might have been confusing in my previous post).

I am using a dataGridView then is hookd up to a dataset that feeds the information to SQL, that explains my update/fill commands up at the top.

How could I accomplish this using a dataGridView/dataset?

there would be multiple rows on the dataGridView, but only one row would be selected a time.

Thank you for the help!


it's the same for the datagrid or view...

during the change of the checkbox u got to select the currenctly selected row as i showed above and then manipulate that row

that change would automatically gets reflected in the data table contained in ur dataset  and when u call the update command of the dataadpater this will be saved to the database

this.rescueScheduleDataSet.jobIntake -- this is ur table right

this.rescueScheduleDataSet.jobIntake .select("ur condition") would give u the necessary rows
Yes that is my table. Thank you for the help again. Do you have an example of code for doing this? C# is still much a learning process for me.

k..can u give the field name of ur key

lets say its "FIELDNAME"

and the field name of the stuff u want to change is "changefield"
and say u have the key in  variable 'keyvar'


check box changed event()
         System.Data.DataRow []Arow = this.rescueScheduleDataSet.jobIntake.Select
         ("FIELDNAME ='"+keyvar+"'");//this would select the row..
         if (checkBox1.enable == true)
                       Arow[0]["changefield"] = "Y";
                      Arow[0]["changefield"] = "N";

save click event u dont have to change anything....

good luck....


hope this works :-)
Hey gauthampj,
I think i have one last question. I am confused on what you mean by fieldname and changefield? and keyvar?

sorry I am a noob :P


k.. each row in ur table would have some column with which it could be uniquely identified ...k...

fieldname is the "Field Name" of this column..k


Change Field is the column whose value u have to whose value has to be set to "y" or "n"..kk

still if u dont get this can u post how u do this

<When the user clicks on the DataGridView, the textboxes that are databound display the related data>

i'll try to explain from there...

"still if u dont get this can u post how u do this

<When the user clicks on the DataGridView, the textboxes that are databound display the related data>"

I do this by selecting the textbox, going to peropeties. Expand DataBindings, click Text, then:
other Data Sources
     datagridView1 List Instances
                       *Select Column*

Thats how I bind data from the textboxes and other controls to the dataGridView.


Select ColumnNAme of the column u choose for the text box containing "Y" and "N" would be ur changefield...

do u have any column in ur datatable with which u could uniquely identify a record...
I think i am starting to get where you are going.

I do not think I have any column in your datable which I could uniquely identify a record. The information is variable, all the information in the dataTable is based off of user entries.

This is where my changeField goes, my estimateColumn.

            System.Data.DataRow[] Arow = this.rescueScheduleDataSet.jobIntake.Select();
            ("FIELDNAME ='" + KEYVAR + "'");
            if (estimateBox.Enabled == true)
                Arow[0]["estimateColumn"] = "Y";
                Arow[0]["estimateColumn"] = "N";

Thank you for your patience with this !
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
k.. the page didnt refresh
if u dont have one then u will have to introduce one into that datatable like a serial number or something like that