请教一个简单问题,为何老提示:未定义类型SqlConnection,谢谢,在线等待(50分)

  • 主题发起人 主题发起人 nj_herry
  • 开始时间 开始时间
N

nj_herry

Unregistered / Unconfirmed
GUEST, unregistred user!
请教一个简单问题,为何老提示:未定义类型SqlConnection,谢谢,在线等待
原码如下:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand
'同数据库进行连接,采用sql server数据库
MyConnection = New SQLConnection("server='ZHONG';uid=sa;pwd=;database=ny")
'执行SQL操作
MyCommand = New SQLDataSetCommand("select * from userlist",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "userlist")
MyDataGrid.DataSource=ds.Tables("userlist").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<center>
 
<%@ Import Namespace="System.Data.SqlClient" %>
 
是不是还有什么东西没装呢
系统已装:MDAC2。8,。NET FRAMEWORK,没有数据库连接的ASPX文件在IE中运作正常
 
TO:onlyonekgx
首先感谢你的回答,加上去以后又出现未定义类型“SQLDataSetCommand”
可不可以把所有需要加的全告诉我,谢谢
 
SQLDataSetCommand????
SqlDataAdapter
SqlCommand
 
to onlyonekgx:
SQLDataSetCommand????
SqlDataAdapter
SqlCommand
什么意思?
加上了还是不行,我是这样加的
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlDataAdapter" %>
<%@ Import Namespace="System.Data.SqlCommand" %>
 
不是你说的那样,
Sub Page_Load(Src As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand ///SQLDataSetCommand->SqlCommand
'同数据库进行连接,采用sql server数据库
MyConnection = New SQLConnection("server='ZHONG';uid=sa;pwd=;database=ny")
'执行SQL操作
MyCommand = New SQLDataSetCommand("select * from userlist",MyConnection)
MyCommand = New SQLCommand("select * from userlist",MyConnection) //////////////////////////////// 不过我想你应该是想这样 myCommand=New SqlDataAdapter("select * from userlist",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "userlist")
MyDataGrid.DataSource=ds.Tables("userlist").DefaultView
MyDataGrid.DataBind()
End Sub
但是我看你的代码应该是想使用 SqlDataAdapter 而不是想 SqlCommand
 
<%@ Import Namespace="System.Data.SQL" %> 存在该命名空间么?
还有,数据库连接用数据适配器SqlDataAdapter就可以了,你可以SqlDataAdapter.Fill(dt,""). 或者用SqlCommand,再 SqlDataReader dr = SqlCommand.ExecuteReader(CommandBehavior.CloseConnection).就可以了/区别:SqlCommand在生成数据集前
SqlConnection必须Open.即:SqlConnection.Open();
 
在开头加上这一句<%@ Import Namespace="System.Data.SqlClient" %>试一下!!!
 
谁可以给我全部与数据库连接的基本操作,以上我试了还是不能通过。谢谢!
 
加上语句using System.Data.SqlClient;试试
 
重新改了一下程序还是不行,提示:未定义类型“ADOConnection
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlDataAdapter" %>
<%@ Import Namespace="System.Data.SqlCommand" %>
<%
Dim strConnString as String
strConnString = "Provider=SQLOLEDB;
Data Source=zhong;
" &amp;
_
"Initial Catalog=yuejin;
User ID=sa"
'创建对象ADOConnection
Dim objConn as ADOConnection
objConn = New ADOConnection
'设置ADOCOnnection对象的连接串
objConn.ConnectionString = strConnString
objConn.Open() '打开数据链路
'创建SQL字符串
Dim strSQL as String = "SELECT * FROM userlist"
'创建对象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" Width="840px" Height="128px" BorderStyle="None" GridLines="Vertical"
BorderWidth="1px" BorderColor="#999999" BackColor="White" CellPadding="3">
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#DCDCDC"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
</asp:DataGrid>
</BODY>
</HTML>
 
后退
顶部