Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VS C# Datagridview not saving data

Posted on 2013-11-04
12
Medium Priority
?
576 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

618 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