Solved

VS C# Datagridview not saving data

Posted on 2013-11-04
12
573 Views
Last Modified: 2013-11-05
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
Comment
Question by:rwheeler23
  • 8
  • 4
12 Comments
 

Author Comment

by:rwheeler23
ID: 39623315
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
 

Author Comment

by:rwheeler23
ID: 39623318
I will actually attach the screenshot this time.
ScreenShot.bmp
0
 
LVL 4

Expert Comment

by:ShareD_Point
ID: 39623339
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:rwheeler23
ID: 39623901
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
 

Author Comment

by:rwheeler23
ID: 39623938
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
 
LVL 4

Accepted Solution

by:
ShareD_Point earned 500 total points
ID: 39624219
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
 

Author Comment

by:rwheeler23
ID: 39625837
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
 

Author Comment

by:rwheeler23
ID: 39625874
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
 

Author Comment

by:rwheeler23
ID: 39625944
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
 
LVL 4

Expert Comment

by:ShareD_Point
ID: 39626167
Good to know you figured it out.
0
 

Author Closing Comment

by:rwheeler23
ID: 39626193
Thanks for stearing me in the right direction.
0
 
LVL 4

Expert Comment

by:ShareD_Point
ID: 39626276
@rwheeler23   You are welcome.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question