初学者的问题,请进!

xh416 2004-11-18 08:33:15
有如下代码,看看有什么问题?
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<!--DataSet 要引用system.data,数据库连接要用到system.data.sql-->
<html>

<script language="vb" runat=server>

sub Page_Load(o as object,e as eventargs)
dim MyConnection as SQLConnection
dim MyStr as String
dim MyDataSetCommand as SQLDataSetCommand
dim MyDataSet as New DataSet

If Not IsPostBack

MyConnection=New SQLConnection("server=localhost;uid=sa;pwd=z1x2c3;database=pubs")

MyStr="Select au_lname,au_fname from authors"

MyDataSetCommand=New SQLDataSetCommand(Mystr,MyConnection)
MyDataSetCommand.FillDataSet(MyDataSet,"Authors")

Session("MyDs")=MyDataSet

Else
MyDataSet=Session("MyDs")

if MyDataSet is Nothing
Response.Write("无法取得数据")
else
Select Case DpDnLst.SelectedItem.text
case "Repeater"
Response.write _
("<center>以<I>Repeater</I>控件显示数据</center>")
db1.datasource=MyDataSet.tables("authors").defaultview
db1.databind

panel1.visible=True
panel2.visible=False
panel3.visible=False
case "DataList"
Response.write _
("<center>以<B>DataList</B>控件显示数据</center>")
db2.datasource=MyDataSet.tables("authors").defaultview
db2.databind

panel1.visible=False
panel2.visible=True
panel3.visible=False


case "DataGrid"
Response.write _
("<center>以<U>DataGrid</U>控件显示数据</center>")
db3.datasource=MyDataSet.tables("authors").defaultview
db3.databind

panel1.visible=False
panel2.visible=False
panel3.visible=True

case else
End Select

end if
End If
end sub
</script>
<head>
<title>
数据绑定技术试验
</title>
</head>

<body bgcolor=#ffffff>
<center>
<h2>DataSource试验</h2>
<hr>

<form runat=server>
请选择控件类型: 
<asp:DropDownList id="DpDnLst" runat=server>
<asp:Listitem>Repeater</asp:Listitem>
<asp:Listitem>DataList</asp:Listitem>
<asp:Listitem>DataGrid</asp:Listitem>
</asp:DropDownList>
  
<asp:button text="提交" runat=server/>
<hr>

<!--定义三个画板,根据下拉列表的选择,使指定的画板可见-->

<!-- 画板一 :定义一个Repeater控件 -->
<asp:panel id="panel1" visible=false runat=server>
<asp:repeater id="db1" runat=server>
<!--定义Repeater控件显示的表头 -->
<template name="headertemplate">
<table>
<tr>
<td>
姓氏
</td>
<td>
名字
</td>
</tr>
</template>

<!--定义Repeater控件数据显示的格式 -->
<template name="itemtemplate">
<tr>
<td>
<%# databinder.eval(container.dataitem,"au_lname") %>
</td>
<td>
<%# databinder.eval(container.dataitem,"au_fname") %>
</td>
</tr>
</template>

<!--定义Repeator控件显示的表尾 -->
<template name="footertemplate">
</table>
</template>
</asp:repeater>
</asp:panel>

<!-- 画板二:定义一个DataList控件 -->
<asp:panel id="panel2" visible=false runat=server>
<asp:datalist id="db2" runat=server>
<!--定义datalist的显示格式为:姓氏----名字 -->
<template name="itemtemplate">
<%# databinder.eval(container.dataitem,"au_lname") %>
----
<%# databinder.eval(container.dataitem,"au_fname") %>
<br>
</template>
</asp:datalist>
</asp:panel>

<!-- 画板三:定义一个DataGrid控件 -->
<asp:panel id="panel3" visible=false runat=server>
<asp:datagrid id="db3" runat=server>
</asp:datagrid>
</asp:panel>

</form>
</center>
</body>
</html>


错误有如下提示:

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
...全文
98 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xh416 2004-11-19
  • 打赏
  • 举报
回复
没人帮我修改吗?
xh416 2004-11-18
  • 打赏
  • 举报
回复
这应该是最简单的打开数据库呀!
很多例子都是这样的,都是一样的效果,不知错是出在哪里
Netmark 2004-11-18
  • 打赏
  • 举报
回复
既然初学,一开始就先不要搞那么复杂的问题吧
步步来,我觉得比较好
xh416 2004-11-18
  • 打赏
  • 举报
回复
急学!
xh416 2004-11-18
  • 打赏
  • 举报
回复
哪怎么修改呢,我也是看别人的例子!
WZCNet 2004-11-18
  • 打赏
  • 举报
回复
我没见过
dim MyDataSetCommand as SQLDataSetCommand

SQLDataSetCommand是个什么东西啊,应该是用SqlDataAdapter
xh416 2004-11-18
  • 打赏
  • 举报
回复
在线等回复!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧