Solved

VS C# Datagridview not saving data

Posted on 2013-11-04
12
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 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