[关闭]错误未在警告框中显示:

编程入门 行业动态 更新时间:2024-10-26 13:20:25
本文介绍了[关闭]错误未在警告框中显示:-(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 我正在尝试 在警报框中显示"importsites不是一个有效的名称...."错误,当上载的excel文件具有错误的选项卡名称,但是不显示时,它会掉线. 如果文件格式错误,则显示警告框,但如果选项卡名称不同,则不会显示 非常感谢所有帮助:-)

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 :-)

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

推荐答案

",objXConn) ' 错误恢复下一个 ' objXConn.Close() Dim objDataAdapter As 新建 OleDbDataAdapter() ' 如果objCommand什么都没有, ' 其他 objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet() objDataAdapter.Fill(objDataSet," xldata" ) ' 查看您在gridview中上传的数据.这将检查此时是否有空行,并在必要时更改颜色 GridView1.DataSource = objDataSet.Tables( 0 ).DefaultView GridView1.DataBind() ' 如果结束 objXConn.Close() ButtonImport.Enabled = importButtonEnabled 如果 ButtonImport.Enabled = 错误 然后 lblerror.ForeColor = System.Drawing.Color.Red lblerror.Text = " 文件出错" 结束 如果 捕获,例如 As 异常 Response.Write(" < script LANGUAGE = JavaScript type =""text/javascript">" ) Response.Write(" 警报('" & ex.Message.ToString& " ')" ) Response.Write(" </script>" ) 如果 objXConn.State = ConnectionState.打开然后 objXConn.Close() 结束 如果 结束 尝试 结束 子 ", 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

看看RegisterStartupScript方法 msdn.microsoft/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx [ ^ ] Have a look at the RegisterStartupScript method msdn.microsoft/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx[^]

嗨 我的队友找到了解决方案,并且我可以相信:-(我花了2天的时间来维护Serachin,原因是捕获的错误中有一个单引号",将其排除在外,所以解决方案如下 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 Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">") Response.Write("alert('" & ex.Message.ToString.Replace("'", """") & "')") Response.Write("</script>")

感谢所有张贴tho:-)

thanks for everyone who posted tho :-)

更多推荐

[关闭]错误未在警告框中显示:

本文发布于:2023-10-16 06:08:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框中   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!