none
Excel to dataset to database RRS feed

  • Question

  • I'm using the following code to get data from an excel file, to fill one of the tables of my database...

    I can see the data is arriving to the dataset because I'm able to see it in the datagridview of the table...

    But when I push the save button and close the app, the database stays unchanged...

    I can see that after I get the data to the dataset, the rows state is "unchanged" soI've changed one of the rows state to added, and it worked... If I try to do this to every row (which I don't see as a good practice...) I get an error....

    Those someone knows a better way, because I really think It can't be that hard....

     

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'TODO: This line of code loads data into the 'ArmaGestDbDataSet.Componente' table. You can move, or remove it, as needed.

    Me.ComponenteTableAdapter.Fill(Me.ArmaGestDbDataSet.Componente)

    End Sub

    Private Sub ComponenteBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComponenteBindingNavigatorSaveItem.Click

    Me.Validate()

    Me.ComponenteBindingSource.EndEdit()

    Me.ComponenteTableAdapter.Update(Me.ArmaGestDbDataSet.Componente)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cn As System.Data.OleDb.OleDbConnection

    Dim cmd As System.Data.OleDb.OleDbDataAdapter

    cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _

    "data source=C:\Livro1.XLS;Extended Properties=Excel 8.0;")

    ' Select the data from Sheet1 of the workbook.

    cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Folha1$A1:L4]", cn)

    cn.Open()

    cmd.Fill(Me.ArmaGestDbDataSet.Componente)

    cn.Close()

     

    End Sub

     

     

     

    Wednesday, June 13, 2007 5:50 PM

All replies

  • Hi spöne,
      I am moving this thread from Visual Basic Express Edition forum to the .NET Framework Data Access and Storage forum, since the issue is related to ADO.net. There are more ADO.net experts in the .NET Framework Data Access and Storage forum.
    Thanks for your understanding!
    Monday, June 18, 2007 7:21 AM