Chuyển data excel vào Datagridview ( VB.Net) (1 người xem)

  • Thread starter Thread starter ktttnotc
  • Ngày gửi Ngày gửi
Liên hệ QC

Người dùng đang xem chủ đề này

ktttnotc

Thành viên mới
Tham gia
8/9/09
Bài viết
1
Được thích
0
em có đoạn code kết nối
Mã:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyConnection [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbConnection
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DtSet [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.DataSet
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyCommand [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbDataAdapter
MyConnection = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbConnection([/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\lichbayngay.xls';Extended Properties=Excel 8.0;"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
MyCommand = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbDataAdapter([/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"select * from [Sheet1$]"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], MyConnection)
MyCommand.TableMappings.Add([/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"Table"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"Test"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
DtSet = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Exception
MsgBox(ex.ToString)
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/COLOR][/SIZE]
có thể chuyển data vào được datagridview nhưng không thể kiểm tra, lọc được data khi add vào datagridview , Bác nào có thể chỉnh sửa để có thể kiểm tra được data trước khi đưa vào datagridview chỉ em với
Thanks !!!!
 

Bài viết mới nhất

Back
Top Bottom