[ MishaP @ 24.02.2009. 13:14 ] @
Da li neko ima kod kojim se uvoze podaci iz excel tabele u datagridview tabelu ili u SQL server tabelu. |
[ MishaP @ 24.02.2009. 13:14 ] @
[ Igor Gajic @ 24.02.2009. 16:31 ] @
Code: OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + datoteka + ";Extended Properties=\"Excel 8.0;HDR=Yes\""); OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", conn); DataTable Tabela=new DataTable(); Adapter.Fill(Tabela); Ovo je da ucitas podatke iz .xls datoteke. Takodje opcija HDR oznacava da je prvi red u stvari zaglavlje tabele, tj. sadrzi imena kolona. [ MishaP @ 24.02.2009. 18:11 ] @
Morao sam malo da korigujem tvoj kod i izgleda ovako
Dim conn = New OleDbConnection() conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0; DataSource= + c:\\Novembar_detalji.xls + ;Extended Properties=\Excel 8.0;HDR=Yes\") Dim Adapter = New OleDbDataAdapter("SELECT * FROM [Sheet0$]", conn) Dim Tabela = New DataTable() Sheet01TableAdapter.Fill(Tabela) i sada mi se javlja greška. Unable to cast object of type 'System.Data.DataTable' to type 'Sheet01DataTable'. [ Igor Gajic @ 24.02.2009. 18:22 ] @
Jel ti ovo direktno iz koda ???
posto imas : Code: Dim Adapter = New OleDbDataAdapter("SELECT * FROM [Sheet0$]", conn) Dim Tabela = New DataTable() Sheet01TableAdapter.Fill(Tabela) Treba da ide: Code: Adapter.Fill(Tabela) [ MishaP @ 24.02.2009. 18:51 ] @
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn = New OleDbConnection() conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0; DataSource= + c:\\Novembar_detalji.xls + ;Extended Properties=\Excel 8.0;HDR=Yes\") Dim Adapter = New OleDbDataAdapter("SELECT * FROM [Sheet0$]", conn) Dim Tabela = New DataTable() 'Sheet01TableAdapter.Fill(Tabela) Adapter.Fill(Tabela) End Sub OPet isto greska je Could not find installable ISAM. [ Igor Gajic @ 24.02.2009. 19:16 ] @
Probaj sa :
Code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn = New OleDbConnection() conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0; DataSource=c:\\Novembar_detalji.xls ;") Dim Adapter = New OleDbDataAdapter("SELECT * FROM [Sheet0$]", conn) Dim Tabela = New DataTable() 'Sheet01TableAdapter.Fill(Tabela) Adapter.Fill(Tabela) End Sub [ MishaP @ 24.02.2009. 19:29 ] @
Neće Igore, ista greška. Samo jedno zapažanje, ne vidim kako se u kodu puni baš moja tabela, sheet0 recimo,
[ Igor Gajic @ 24.02.2009. 20:30 ] @
Evo ti projekat koji sigurno radi.
I kako imas u dokumentu Sheet0 ? valjda krece od sheet1 ? Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|