When i choose the excel file in the file upload control the sheets come into the listbox.
The problem is when i choose the particular sheet from the listbox and then click on the upload button the data is not going to database.
protected
void btnChooseSheet_Click(object sender, EventArgs e)
{
// System.Data.DataTable dt = null;
try
{
string path1 = FileUpload1.PostedFile.FileName;
string oledbconnection1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path1 + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
//Label2.Text = path1.ToString();
abc = path1.ToString();
Label2.Text = abc.ToString();
objConn =
new OleDbConnection(oledbconnection1);
objConn.Open();
DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
Response.Write(
"hello");
}
String[] sheetsname = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
sheetsname[i] = dr[
"TABLE_NAME"].ToString();
ListBox1.Items.Add(sheetsname[i].ToString());
i++;
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
This code is inserts the sheets into listbox. Further i want to upload the particular sheet from the listbox into database.
So guys any suggestion.....pls help..
Thanks in Advance...