我在aspx页面中想嵌入vbscript代码,抓取资料库信息,结果信息抓出来了,但是不知道怎么显示,我是用的一个public function 返回一个string值,后来用<% function() %>显示不出任何东西来,也用了response.write(function()),还试了<script language="vbscript">function()</script>,甚至用了asp控件,<asp:label text='<% function() %>'></label>结果都不行,发帖后有人告诉我用<div id=div1></div>
<script language="vbscript">
div1.innerhtml = function()
</script>结果提示页面有错误:“型态不符合function”,还有在连接数据库时Dim ConnectionString As String = "User ID......"也在"User"前面报错(internet Explorer指令码错误):“必须提供陈述式”。请问是什么原因??

解决方案 »

  1.   

    有啊,返回一个名字,我在.net里面试验成功了,但是在frontpage里面编辑时就不行了,显示不出来
      

  2.   

    代码如下:<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>New Page 1</title>
    <script language=vbscript>
            Public Function Name() As String
            Dim ConnectionString As String = "User ID=......"
            Dim UserName() As String = HttpContext.Current.User.Identity.Name.Split("\")
            Dim SQL As String = "select ......"
            Dim cmd As System.Data.SqlClient.SqlCommand
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConnectionString)
            conn.Open()
            cmd = New System.Data.SqlClient.SqlCommand(SQL, conn)
            dr = cmd.ExecuteReader
            If dr.Read Then
                Name = dr.Item("Name").ToString.Trim
            Else
                Name = ""
            End If
            dr.Close()
            conn.Close()
        End Function </script></head>
    <body>
    <div id="div1"></div>
    <script language="vbscript">
     div1.innerHTML = Name() 
    </script>
    </body>
    </html>
      

  3.   

    楼主,为什么不用VB.NET 或C#呢?
      

  4.   

    我是菜鸟,才开始接触网页编程不久,对于它们间的具体区别还不太了解。他们实现起来有很大的差别吗??我不知道aspx页面的vb代码怎么加
      

  5.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>New Page 1</title>
    <script language=vbscript>
            Public Function Name() As String
            Dim ConnectionString As String = "User ID=......"
            Dim UserName() As String = HttpContext.Current.User.Identity.Name.Split("\")
            Dim SQL As String = "select ......"
            Dim cmd As System.Data.SqlClient.SqlCommand
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConnectionString)
            conn.Open()
            cmd = New System.Data.SqlClient.SqlCommand(SQL, conn)
            dr = cmd.ExecuteReader
            If dr.Read Then
                Name = dr.Item("Name").ToString.Trim
            Else
                Name = ""
            End If
            dr.Close()
            conn.Close()
        End Function</script></head>
    <body>
    <div id="div1"></div>
    <%=Name()%>
    </body>
    </html>
      

  6.   

    谢谢楼上的兄弟先,不过aspx页面好像不支持<% %>标签,这种方法我试过了,会报错
    編譯錯誤 
    描述: 資源編譯無法完成 (錯誤發生於服務要求)。請檢閱下列的特定錯誤詳細資料,並視情況修改您的原始程式碼。 編譯器錯誤訊息: BC30451: 名稱 'GetEmpName' 未宣告。
    原始程式錯誤:
    行 29: <%=GetEmpName%> 
      

  7.   

    TO:pisco(pisco)
    你上面的代码肯定不行的,vbscript是在客户端运行,你在里面连接数据库根本就不行,
    你最好用服务端的代码,然后用label显示返回的内容就行了
    大概做法如下:
    先添加label控件label1
    <script language=vb runat=server>      //一定要加runat=server
          Public Function Name() As String
            Dim ConnectionString As String = "User ID=......"
            Dim UserName() As String = HttpContext.Current.User.Identity.Name.Split("\")
            Dim SQL As String = "select ......"
            Dim cmd As System.Data.SqlClient.SqlCommand
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConnectionString)
            conn.Open()
            cmd = New System.Data.SqlClient.SqlCommand(SQL, conn)
            dr = cmd.ExecuteReader
            If dr.Read Then
                Name = dr.Item("Name").ToString.Trim
            Else
                Name = ""
            End If
            dr.Close()
            conn.Close()
        End Function
        label1.Text=Name()     //赋给label1的Text属性,vb不怎么会,不知道这句赋值是不是的,错了自己改改
    </script>
      

  8.   

    我用的是sps2003,不支持服務器端代碼的說,有runat=server就報錯,狂暈