Tuesday, January 20, 2009

Loading Excel File C# & VB

HI
this is the code for Loading excel file data to DataSet

String strConn = "";
String str =""; //should assign the name of the excel file
Dataset myDataSet = new DataSet();
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + str + ";" +
"Extended Properties=Excel 8.0;";
myDataSet = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
myCommand.Fill(myDataSet, "ExcelInfo");


VB Code
Dim strConn As String = ""
Dim str As String = ""

Dim myDataSet As Dataset = New DataSet()
strConn = ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=") + str & ";" & "Extended Properties=Excel 8.0;"
dt = New DataTable()
myDataSet = New DataSet()
Dim myCommand As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myCommand.Fill(myDataSet, "ExcelInfo")

No comments:

Post a Comment