System.Data.DataException

DekaFlash

Well-known member
Joined
Feb 14, 2006
Messages
117
Programming Experience
1-3
Resolved - System.Data.DataException

When I try to edit data displayed within my DataGrid I get the following error dialog.

The Dialog Box is titled DataGridView Default Error Dialog and the message reads

The following exception occured in the DataGridView:

System.Data.DataException. Cannot set lf1.
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object
Value

at System.Data.DataColumnPropertyDescriptor.SetValue(Object Component,
Object Value)

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.
PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex,
Object value)

Please advise thanks.
 
Last edited:
First up, a DataGridView is not a DataGrid. They are two different controls so please ensure you use the proper names for everything in future to avoid confusion.

You have presumably entered a value into your grid that is not valid for the underlying data source. I believe the dialogue would have also told you that if you want to provide your own error message, which might be more informative to the user, then you need to handle the DataError event of the grid.
 
Data Grid View Exception

Please find a screen shot as requested

datagridview.jpg
 
well now, that doesnt say "Cannot Set lf1" but that's a minor thing

Now I want to know exactly what you do to cause this to appear after starting a debug version of your program. Every mouse click, mouse point, movement, new window and keypress..
 
1) I put my password in and click ok.
2) I click the date / race details button, this displays the data entry form.
3) I click select date to load today's data.
4) I click a button to go into the calculation screen.
5) I click calculate and then I get the error as displayed in the screen shot.

Someone suggested using ado.net and sqlcommandbuilder and the like rather then
table adapters, what do you suggest?
 
TableAdapters ARE part of ADO.NET. That's got nothing to do with it anyway. As I said in my previous post, the dialogue is telling you that you're able to handle the DataError event. If you do that you may be able to get more information. Then again, maybe not. Regardless, you are entering a value into your grid that is not valid for the underlying data source. What value is it trying to enter? What type of data does that column expect? Are there any constraints on the values that column can contain?
 
Back
Top