主题:关于使用.NET连接数据库的问题,请各位大侠帮忙
我在用ADO.net连接数据库时,运行的画面中出现错误,显示如下:
Compiler Error Message: BC30002: Type 'ADOConnection' is not defined.
这是不是说ADOConnection这个东西不存在?我该如何解决?下面是我写的源代码
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<%
'设置连接串
dim strConnString as String
strConnString = "Provider=SQLOLEDB; Data Source=(Local);" & "Initial Catalog=pubs; User ID=sa"
'创建对象ADOConnection
dim objConn as ADOConnection
objConn = new ADOConnection
'设置ADOConnection对象的连接串
objConn.ConnectionString = strConnString
objConn.Open() '打开数据链路
'创建SQL字符串
dim strSQL as String="SELECT * FROM authors"
'创建对象ADODatasetCommand和Dataset
dim objDSCommand as ADODatasetCommand
dim objDataset as Dataset = new Dataset
objDSCommand = new ADODatasetCommand(strSQL, objConn)
'填充数据到Dataset,并将数据集合命名为 Author Information
objDSCommand.FillDataSet(objDataset, "Author Information")
objConn.Close() '关闭数据链路
objConn = Nothing '清除对象
Authors.DataSource = objDataset.TAbles("Author Information").DefaultView
Authors.DataBind()
%>
<html>
<body>
<asp:DataGrid id="Authors" runat="server" />
</body>
</html>
Compiler Error Message: BC30002: Type 'ADOConnection' is not defined.
这是不是说ADOConnection这个东西不存在?我该如何解决?下面是我写的源代码
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<%
'设置连接串
dim strConnString as String
strConnString = "Provider=SQLOLEDB; Data Source=(Local);" & "Initial Catalog=pubs; User ID=sa"
'创建对象ADOConnection
dim objConn as ADOConnection
objConn = new ADOConnection
'设置ADOConnection对象的连接串
objConn.ConnectionString = strConnString
objConn.Open() '打开数据链路
'创建SQL字符串
dim strSQL as String="SELECT * FROM authors"
'创建对象ADODatasetCommand和Dataset
dim objDSCommand as ADODatasetCommand
dim objDataset as Dataset = new Dataset
objDSCommand = new ADODatasetCommand(strSQL, objConn)
'填充数据到Dataset,并将数据集合命名为 Author Information
objDSCommand.FillDataSet(objDataset, "Author Information")
objConn.Close() '关闭数据链路
objConn = Nothing '清除对象
Authors.DataSource = objDataset.TAbles("Author Information").DefaultView
Authors.DataBind()
%>
<html>
<body>
<asp:DataGrid id="Authors" runat="server" />
</body>
</html>