Click here to Skip to main content
16,013,642 members

Comments by Member 10599847 (Top 10 by date)

Member 10599847 1-Jun-14 7:58am View    
Here is the complete code
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
if (UploadExp.HasFile)
{
string path = UploadExp.FileName;
UploadExp.SaveAs(Server.MapPath(".\\Uploadfiles\\" + path));
OleDbConnection oconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".\\UploadFiles\\" + path) + ";Extended Properties=Excel 8.0");
oconn.Open();
OleDbCommand ocmd = new OleDbCommand("Select * from [Sheet1$]", oconn);
OleDbDataAdapter odap = new OleDbDataAdapter(ocmd);
dl.sqldset = new DataSet();
odap.Fill(dl.sqldset);
GridView1.DataSource = dl.sqldset;
GridView1.DataBind();
oconn.Close();


}
else
{
string msg = "<script language='javascript'> alert(' Please Select a file ')</script>";
Page.RegisterStartupScript("popup", msg);
return;
}
}
catch (Exception ex)
{
string Err = "<script language='javascript'> alert(' " + ex.Message + "')</script>";
Page.RegisterStartupScript("popup", Err);
return;
}
}
Member 10599847 1-Jun-14 7:56am View    
I am not sure if I have understood your comments fully. Still I will try to explain the situation, hopefully you can find the difference. The application is developed in my local system, which means all the programs and relevant folders (in this case 'UploadFiles') are located in my local hard disk. But it points to the database in our remote server. When I run the application in a debugging mode or otherwise (i.e. by clicking View in Browser) with the same codes, the gridview is populated with the data in the excel sheet. But after the application is deployed into a dedicated database server when me or any other user logs on to the application from the browser, this particular module fails to work. I may mention here that the application was earlier located in a different server and the same code was working fine. Recently it has been moved to a new server with a different IP address. I don't know if I have made it clear to you
Member 10599847 1-Jun-14 7:01am View    
Try-catch block is already there, it does not display any error message
Member 10599847 1-Jun-14 6:30am View    
In the first place, gridview is not populated. Secondly, i tried to display a message before and after the 'oconn.open'. The message after the command is not displayed. Hence it is evident, for some reason the programs gets terminated at this line. If i run the same code from programming environment (my PC) instead of the server, it gets executed.
Member 10599847 30-Mar-14 2:11am View    
on page load event I did manage that. As suggested I am binding data on every event, it works. Thanks.