rs8cap Posted July 24, 2013 at 04:15 PM Report #519804 Posted July 24, 2013 at 04:15 PM Boa tarde, necessito de criar um procedimento de forma a extrair informação de uma folha de excel para um datagrid de VB 2008 mas coloco este código e dá sempre um erro. Alguém me pode dizer porquê? o código que utilizo é este: Imports System.Data.OleDb Public Class Fecho_Mes Private da As OleDbDataAdapter Private dt As DataTable Dim conexao_Excel As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=c:\Users\ricardo.pedro\Downloads\HF_ AO a 201306.xls;Extended Properties=Excel 14.0;" Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click Dim da as String = Nothing ' cria um novo dataadapter da = New OleDbDataAdapter("SELECT * FROM [HF_ AO a 201306$]", conexao_Excel) ' ' preenche a tabela com dados da planilha Excel dt = New DataTable da.Fill(dt) ' define a chave primaria dt.PrimaryKey = New DataColumn() {dt.Columns(0)} ' registros somente podem ser inseridos usando esta tecnica dt.DefaultView.AllowDelete = False dt.DefaultView.AllowEdit = True dt.DefaultView.AllowNew = True ' vincula o modo de visao padrão da tabela ao datagrid DataGridView1.DataSource = dt.DefaultView End Sub End Class
bioshock Posted July 24, 2013 at 05:21 PM Report #519817 Posted July 24, 2013 at 05:21 PM É um concurso para adivinharmos o erro? da.Fill(dt, 0)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now