Avatar of JasonWinn
JasonWinn
 asked on

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);

        }
C#

Avatar of undefined
Last Comment
Gautham Janardhan

8/22/2022 - Mon
Gautham Janardhan

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

ASKER
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 Janardhan

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..
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
JasonWinn

ASKER
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 Janardhan

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"

JasonWinn

ASKER
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!

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Gautham Janardhan

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
JasonWinn

ASKER
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 Janardhan

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



}
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Gautham Janardhan

hope this works :-)
JasonWinn

ASKER
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 Janardhan



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...






Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
JasonWinn

ASKER
"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 Janardhan

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...
JasonWinn

ASKER
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 !
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Gautham Janardhan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gautham Janardhan

k.. the page didnt refresh
Gautham Janardhan

if u dont have one then u will have to introduce one into that datatable like a serial number or something like that