日期:2014-04-22  浏览次数:20970 次

错误一:运行代码时出现如下错误:
-------------------------------------------------------------------
编译器错误信息: BC30002: 未定义类型“ADOConnection”。

源错误:
行 11: <Script Language="VB" Runat="Server">
行 12: Sub Button1_Click(sender As Object, E As EventArgs)
行 13: Dim cnA As ADOConnection=New ADOConnection
行 14: Dim cmA As ADOCommand=New ADOCommand
行 15: cnA.Provider="Microsoft.Jet.OLEDB.4.0"
源文件: g:\inetpub\wwwroot\WebApplication1\WebForm3.aspx 行: 13
-----------------------------------------------------------------------------
这是因为NameSpace出错!
使用如下:
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.Oledb" %>
对应变量声明为:
dim myconn as OledbConnection
dim mycommand as OledbCommand

<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.SqlClient" %>
对应变量声明为:
dim myconn as SqlConnection
dim mycommand as SqlCommand

<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.ODBC" %>
对应变量声明为:
dim myconn as ODBCConnection
dim mycommand as ODBCCommand

测试程序分别如下:
=============================
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.Oledb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<BODY>
<script language="vb" runat="server">
Sub Page_load(Sender As Object, E As EventArgs)
dim ds as dataset
dim myconn as OledbConnection
dim mycommand as OledbCommand
myconn=new Oledbconnection("Provider=SQLOLEDB; Data Source=(local);uid=sa; pwd=pssword; Initial Catalog=database")
myconn.open()
mycommand=new Oledbcommand("select * from user_info",myconn)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Datagrid1.DataSource =myreader
Datagrid1.DataBind()
End Sub
</script>
<P>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<FONT face="宋体">
<asp:datagrid id="DataGrid1" runat="server"></asp:datagrid></FONT>
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</P>
</BODY>
</HTML>

==============================
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<BODY>
<script language="vb" runat="server">
Sub Page_load(Sender As Object, E As EventArgs)
dim ds as dataset
dim myconn as sqlconnection
dim mycommand as SqlCommand
myconn=new Sqlconnection("server=(local); uid=sa; pwd=huangfeng;database=jxjyzb")
myconn.open()
mycommand=new Sqlcommand("select * from user_info",myconn)
Dim myReader As SqlDataReader = myCommand.ExecuteReader(C

[1] [2] [3] 下一页