Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    vb.net 2008 db access - update datagridview popolata da file csv

    Sera a tutti quanti, ho un piccolo quesito, ho necessità di importare un listino preso da un file csv, e questo lo faccio tramite:

    Try
    Dim line As String
    Dim sTemp As String
    Dim campo() As String
    Dim fName As String = "c:\prova.csv"
    Dim sGridRow(8) As String
    Dim lineNumber As Integer = 0
    Dim reader As New IO.StreamReader(fName)
    ProdottiDataGridView.Rows.Clear()
    While reader.Peek <> -1
    line = reader.ReadLine()
    campo = Split(line, ";")
    For i As Integer = 0 To campo.Length - 1
    sTemp = Replace(campo(i), """", "")
    sGridRow(i) = sTemp
    Next
    Me.ProdottiDataGridView.Rows.Add(sGridRow)
    lineNumber += 1
    End While
    Catch ex As Exception
    'Dim risp As Integer
    'risp = MsgBox(ex, 17)
    ' If risp = 2 Then
    'Exit Sub
    'End If
    End Try

    solo che non so come eseguire l'update di tutto il datagridview in db access, per poi applicare chiaramente dei filtri. Ho provato a collegare la datagrid con la tabella ma non viene popolata e quà mi fermo, spero mi possiate aiutare.

    stefano

  2. #2
    Risolto con un ciclo e inserendo nel form 2 datagridview e facendo un insert e copiando i dati da un datagridview ad un altro. magari esiste un metodo più semplice ma per ora mi accontento. inserisco codice per i posteri, chiaramente da adattare secondo esigenze

    For i As Integer = 0 To ProdottiDataGridView.Rows.Count() - 1


    ProdottiBindingSource.AddNew()
    DataGridView1.Rows(i).Cells(1).Value = ProdottiDataGridView.Rows(i).Cells(0).Value
    DataGridView1.Rows(i).Cells(2).Value = ProdottiDataGridView.Rows(i).Cells(1).Value
    DataGridView1.Rows(i).Cells(3).Value = ProdottiDataGridView.Rows(i).Cells(2).Value
    DataGridView1.Rows(i).Cells(4).Value = ProdottiDataGridView.Rows(i).Cells(3).Value
    If ProdottiDataGridView.Rows(i).Cells(4).Value = 1 Then
    DataGridView1.Rows(i).Cells(5).Value = True
    Else
    DataGridView1.Rows(i).Cells(5).Value = False
    End If

    DataGridView1.Rows(i).Cells(6).Value = ProdottiDataGridView.Rows(i).Cells(5).Value
    DataGridView1.Rows(i).Cells(7).Value = ProdottiDataGridView.Rows(i).Cells(6).Value
    DataGridView1.Rows(i).Cells(8).Value = ProdottiDataGridView.Rows(i).Cells(7).Value
    Me.Validate()
    Me.ProdottiBindingSource.EndEdit()
    Me.ProdottiTableAdapter.Update(Me.ClientiDataSet.P rodotti)

    Next
    ProdottiTableAdapter.Fill(Me.ClientiDataSet.Prodot ti)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.