Solved

VS C# Datagridview not saving data

Posted on 2013-11-04
12
568 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now