Search code examples
databasevb.netvisual-studio-2010datagridviewoledb

VB.NET Exception Occurs When Trying To View DataGridView


I have a very simple table in access. The data is stored from VB.NET using the OLEDB adapter. I have a second form which has just a single DataGridView which was dragged/dropped using VS2010 from the Data Sources window.

When trying to view the window the first time no data is shown and the second time an exception occurs and the program closes.

Here is the automatically generated code:

Public Class ViewSent

Private Sub SentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SentBindingNavigatorSaveItem.Click
    Me.Validate()
    Me.SentBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.DbDataSet)
End Sub

Private Sub ViewSent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'DbDataSet.Sent' table. You can move, or remove it, as needed.
    Me.SentTableAdapter.Fill(Me.DbDataSet.Sent)


 End Sub

End Class

The specific column I am facing issues with is a "Text" formatted column and the data being inserted is:

cmd2.Parameters.Add("Time", OleDbType.VarChar).Value = DateTime.Now.ToString().Trim()

In the Immediate window after clicking the Form.ShowDialog() button this message appears: A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll

Also, the data does not load into the datagridview.

After closing the window and then clicking the same button (Not data has been changed at all) this error appears: Input string was not in a correct format.Couldn't store <07/11/2011 00:55:06> in Time Column. Expected type is Int32.


Solution

  • I think what Givelasdougmore is trying to say is, that you shouldnt use Words like "Time" "Update" "Delete" as Columnname in your database

    Try to change the column name "Time" to something like "Creationdatetime" or something like this. Then everything should work