[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 577
  • Last Modified:

VS C# Datagridview not saving data

I have this piece of VS C# code that have copied from my other programs and I know works. For some reason with this dataset it refuses to save the data. The grid appears on the screen, I change any value in the grid and then click a Save button, which I knows gets executed. When I look at the table, the values have not been changed. I need a fresh set of eyes to look at this. What am I missing? I have attached the code that displays the data and well as what is behind the Save button.
DisplayData.txt
SaveData.txt
0
rwheeler23
Asked:
rwheeler23
  • 8
  • 4
1 Solution
 
rwheeler23Author Commented:
Here is a screenshot. The GL Account Number column is the only column that is modifiable. I change values and nothing is saved to the table. I even tried looking up new values and that does not work. You will see the changed values on the screen but the Save does nothing. I even put a MessageBox.Show command to make sure the Save button was being hit.
0
 
rwheeler23Author Commented:
I will actually attach the screenshot this time.
ScreenShot.bmp
0
 
ShareD_PointCommented:
Hi,

Could you plz run SQL profiler while you submit the save button and see what is that actually running in SQL server while you execute

DataDataAdapter.Update(DataDataSet);

If you receive SQL statement with correct input parameters and values as expected, select that specific query and run it in a query analyzer against the database where these records need to be inserted / updated and see what is the result you are getting.

Profiler result may give you clarity on any input parameters and values mismatch / error etc.
Executing the resultant query (using a query analyzer) which is taken from SQL Profiler output will provide details on any issue with database schema, constraints etc.

Another thought:
Did you check by any chance, the grid is getting populated again before the actual update is happening and because of which what ever changes you have done gets nullified and no update happens as there is no delta in dataset.

Hope this helps
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rwheeler23Author Commented:
OK, very strange. I just ran SQL Profiler and I see the statement that populates the grid, the statement updating a flag which occurs right after the commandbuilder call but I do not see anything about the data in the grid being updated. It is as if the code never executes.
0
 
rwheeler23Author Commented:
I put a breakpoint right at the point of the Update command. I suspect it is not supposed to look like this? It appears my dataset is empty.
ConnadBuilder.bmp
0
 
ShareD_PointCommented:
Put a break point on form Load , debug and monitor DataDataSet in a Watch window by submitting  the button.

Add DataDataSet.Tables.Count in Watch window.  Lets find what goes wrong.
0
 
rwheeler23Author Commented:
OK, the value of DataDataSet.Tables.Count is zero and DataDataSet is null. So how can I be showing the data in the grid when the dataset is null????
0
 
rwheeler23Author Commented:
I need to make a correction. I added these two lines:

tc = DataDataSet.Tables.Count
rc = DataDataSet.Tables.Rows.Count

I then added both tc and rc to the Watch Window. As I stepped through these two lines the value of tc went to 1 but the value of rc remained at 0.
0
 
rwheeler23Author Commented:
I found it!. The issue is with the SQL statement.

DataDataCommand.CommandText = "select coalesce(VENDORID,'MISSING'),NUMBER,PURCHASES,CONVERT(CHAR(10),PURCHASEDATE,101) AS DOCDATE,DEBIT,CREDIT,coalesce(ITEMGLCOMBINATION,'MISSING'),ITEMNUMBER from RBS_VendorBatchLoadTransaction where GLACCOUNTMATCHED=0 AND WASIMPORTED=0";

The column I am trying to allow to be editable is ITEMGLCOMBINATION which in the SQL statement is a calculated field. If I change the statement to

DataDataCommand.CommandText = "select coalesce(VENDORID,'MISSING'),NUMBER,PURCHASES,CONVERT(CHAR(10),PURCHASEDATE,101) AS DOCDATE,DEBIT,CREDIT,ITEMGLCOMBINATION),ITEMNUMBER from RBS_VendorBatchLoadTransaction where GLACCOUNTMATCHED=0 AND WASIMPORTED=0";

and then go and change the value in that cell. When I click save the new value is stored.
0
 
ShareD_PointCommented:
Good to know you figured it out.
0
 
rwheeler23Author Commented:
Thanks for stearing me in the right direction.
0
 
ShareD_PointCommented:
@rwheeler23   You are welcome.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now