请各位帮我看一下,以下代码为什么会出错?
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<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
MyConnection = New SQLConnection("server=local;uid=sa;pwd=;database=aaaa")
‘执行SQL操作
MyCommand = New SQLdatasetCommand("select * from bbbb",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "bbbb")
MyDataGrid.DataSource=ds.Tables("adsl").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana"></font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="600"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
/body>
</center>
老是提示出错。提示如下:BC30002: Type 'SQLConnection' is not defined.
要怎样修改才行呢?如果将第二句namespace改为system.data.sqlclient,不会出错,但后面又没有filldataset成员,不知该怎么处理。我在网上看到好多例子也就如上所示,不知是哪错了。望指正。
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<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
MyConnection = New SQLConnection("server=local;uid=sa;pwd=;database=aaaa")
‘执行SQL操作
MyCommand = New SQLdatasetCommand("select * from bbbb",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "bbbb")
MyDataGrid.DataSource=ds.Tables("adsl").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana"></font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="600"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
/body>
</center>
老是提示出错。提示如下:BC30002: Type 'SQLConnection' is not defined.
要怎样修改才行呢?如果将第二句namespace改为system.data.sqlclient,不会出错,但后面又没有filldataset成员,不知该怎么处理。我在网上看到好多例子也就如上所示,不知是哪错了。望指正。
解决方案 »
- 400M大文件怎么上传?
- 帮我具体解释一下绘制图像DrawImage()这个方法
- .net中Control类中Render(HtmlTextWriter writer)中参数writer从哪里传来的?
- ASP.NET操作CSV 文件 更新报错
- 请问...可以在ascx文件中添加自定义控件吗...?
- 用了<script>alert('请先登录');window.open('Main.aspx')遨游拦截 用了Redirect没有必要的提示怎么办啊?
- 生成静态页面,打开源文件的代码很乱,没有想正常编辑的html页面代码那么有规律,如何解决?强烈要求置顶!
- 求救在二级域名之间实现共享cookies的问题:
- 在VB.NET的ASP.NET中,如何弹出一个对话框,并返回是否点击了“确定”按钮,如果点击确定继续执行下面的代码,否则中继执行。
- ASP.NET GridView中,想要点击单元格,然后弹出新窗口。
- csdn上兄弟给的代码?调试不能通过!!!
- 一个并发访问量很大的网站(如:九天音乐等),数据传输用DateSet 还是 DateReader.........请各位高手给点意见
改成
<%@ Import Namespace="System.Data.SqlClient" %>
http://www.ccw.com.cn/htm/app/aprog/01_8_1_4.asp
using System.Data.SqlClient;
using System.Data; SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(cmdText,conn);
//返回SqlDataReader
try
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return rdr;
}
catch
{
return null;
}
finally
{
cmd.Dispose();
}
你找参考书,代码的时候注意看清版本, 有一些老的已经被废弃了。