Monday, April 9, 2012

how to read data from excel file in asp.net

Here will how to read the data from excel and export record information to label.For this i will use data reader which id used to read and forward the data .We can not do the manipulations the data while passing from excel to data reader Asp.net:
using System.Data.OLEDB;
//pageload
OleDbConnection cn=new OleDbConnection("provider=microsoft.jet.oledb.4.0;datasource=e:\\asp.net12\\inventorymdb");
OleDb Command cmd=New OleDb Command("select *from product",cn);
OleDbDataReader dr;
cn.Open():
dr=cmd.ExcuteReader();
while(dr.Read)
{
//arrabge record info into label
lblproductinfo.Text=dr["proid"].ToString()+" "+dr["proname"].ToString();
}
vb:
Dim cn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;datasource=e:\asp.net12\inventorymdb")
Dim cmd As New OleDbCommand("select *from product",cn")
Dim dr As New OleDbDataReader
cn.Open()
dr = cmd.ExcuteReader()
While dr.Read
 'arrabge record info into label
 lblproductinfo.Text = dr("proid").ToString() & " " & dr("proname").ToString()
End While

No comments:

Bel