Problem saving data

Here is what I am trying to do. (IF ANYONE HAS A BETTER WAY TO DO THIS PLEASE LET ME KNOW).

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;
            else
                estimateBox.Checked = false;
            this.Validate();
            this.jobIntakeBindingSource.EndEdit();
            this.jobIntakeTableAdapter.Update(this.rescueScheduleDataSet.jobIntake);


        }

   

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

            this.Validate();
            this.jobIntakeBindingSource.EndEdit();
            this.jobIntakeTableAdapter.Update(this.rescueScheduleDataSet.jobIntake);

        }
LVL 3
JasonWinnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
1.Is the check box in a column of the grid..
JasonWinnAuthor Commented:
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.

Gautham JanardhanCommented:
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..
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

JasonWinnAuthor Commented:
correct.

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.

Thanks!

Gautham JanardhanCommented:
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"

JasonWinnAuthor Commented:
gauthampj,
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!

Gautham JanardhanCommented:
k..

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
JasonWinnAuthor Commented:
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.

Jason
Gautham JanardhanCommented:
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'

then

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";
         else
                      Arow[0]["changefield"] = "N";
}


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

good luck....

Gautham



}
Gautham JanardhanCommented:
hope this works :-)
JasonWinnAuthor Commented:
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

Thanks
Jason
Gautham JanardhanCommented:


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

KEYVAR IS THE VALUE CONTAINED IN THE ROW FOR THE PARTICULAR COLUMN DESCRIBED ABOVE...k


Change Field is the column whose value u have to manipulate...ie 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...






JasonWinnAuthor Commented:
"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
            dataset1
                   table1
                       *Select Column*

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

Jason
Gautham JanardhanCommented:
k..

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...
JasonWinnAuthor Commented:
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";
            else
                Arow[0]["estimateColumn"] = "N";

Thank you for your patience with this !
Gautham JanardhanCommented:
ColumnNAme of the column u choose for the text box containing "Y" and "N" would be ur changefield...


if u have a column which will uniquely identify a row then that columnn's name wouldbe FIELDNAME

lets put an extra text box in the form and bind it to this control ...if u dont want user to see this u could hide it


the we could rewrite the chage event as

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gautham JanardhanCommented:
k.. the page didnt refresh
Gautham JanardhanCommented:
if u dont have one then u will have to introduce one into that datatable like a serial number or something like that
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.