How to fill Records from excel sheet into Datagrid..!


strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:data.xls;Extended Properties=""Excel 8.0;HDR=NO;"""

objConn =

New OleDb.OleDbConnection(strConn)

objConn.Open()

‘sql = "SELECT Project Name FROM [Data$]"

Sql = "SELECT * FROM [Data$]"

Dim objCommand As New OleDb.OleDbCommand(sql, objConn)

Dim objAdapter As New OleDb.OleDbDataAdapter(objCommand)

Dim objDS As New DataSet

objAdapter.Fill(objDS)

‘CbProjectName.DataSource = objDS.Tables(0).DefaultView

‘CbProjectName.DisplayMember = objDS.Tables(0).Columns(1).ColumnName

‘CbProjectName.ValueMember = objDS.Tables(0).Columns(0).ColumnName

Dim dr As DataRow ‘ This code removes empty rows from DataSet

For Each dr In objDS.Tables(0).Rows

If (dr.IsNull(0)) And (dr.IsNull(1)) Then

dr.Delete()

End If

Next

DataGridView1.DataSource = objDS.Tables(0).DefaultView

objConn.Close()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: