Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi
I am trying to get

"importsites is not a valid name...." error to display in the alert box, when the excel file that is uploaded has the incorrect tab name, however it does not display, it just falls through.

An alert box is displayed if the file is in the wrong format but not if the tab name is different

all help is much appreciated :-)

VB
importButtonEnabled = True
      PanelUpload.Visible = False
      PanelView.Visible = True
      PanelImport.Visible = False
      btnBack.Visible = True
      btnBack.Enabled = True

      Dim xConnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & Server.MapPath("SiteTemplate.xls") & ";" & _
                        "Extended Properties=Excel 8.0"
      Dim objXConn As New System.Data.OleDb.OleDbConnection(xConnstr)

      Try
          objXConn.Open()

          Dim objCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM [importsites$]", objXConn)

          'On Error Resume Next
          'objXConn.Close()

          Dim objDataAdapter As New OleDbDataAdapter()

          'If objCommand Is Nothing Then

          'Else

          objDataAdapter.SelectCommand = objCommand

          Dim objDataSet As New DataSet()
          objDataAdapter.Fill(objDataSet, "xldata")

          'view the data you have uploaded in your gridview. this will check for any empty rows at this point and change the colours if necessary
          GridView1.DataSource = objDataSet.Tables(0).DefaultView
          GridView1.DataBind()
          'End If
          objXConn.Close()

          ButtonImport.Enabled = importButtonEnabled
          If ButtonImport.Enabled = False Then
              lblerror.ForeColor = System.Drawing.Color.Red
              lblerror.Text = "ERROR WITH FILE"
          End If

      Catch ex As Exception
          Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">")
          Response.Write("alert('" & ex.Message.ToString & "')")
          Response.Write("</script>")

          If objXConn.State = ConnectionState.Open Then
              objXConn.Close()

          End If

      End Try

  End Sub
Posted
Updated 26-May-11 8:48am
v3

 
Share this answer
 
hi
my team mate found the solution and i can believe it :-( i have spent 2 days serachin for a reason and the issue was that there was a single quote ' in the caught error which was kicking it out so the solution was the following

VB
Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">")
            Response.Write("alert('" & ex.Message.ToString.Replace("'", """") & "')")
            Response.Write("</script>")



thanks for everyone who posted tho :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900