我把一段C#代码改写成了vb的,如下,表格里有7条记录,现在一条也不显示
我是asp转.net的,很多控件都不太理解是怎么回事,帮忙看看怎么回事?
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace = "System.Data"%>
<%@ Import Namespace = "System.Data.Odbc"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Call show_list()
End Sub
Sub show_list()
Using connection As New OdbcConnection(ConfigurationSettings.AppSettings("ConnectionString"))
'创建SQL语句 Dim sql = "select * from wenzhang" Dim da As New OdbcDataAdapter(sql, connection) '创建DataSet对象
'DataSet(ds = New DataSet())
Dim ds As New DataSet da.Fill(ds, "wenzhang") '创建分页类
Dim objpage As New PagedDataSource
'PagedDataSource(objPage = New PagedDataSource()) '设置数据源
objpage.DataSource = ds.Tables
'objPage.DataSource=ds.Tables["authors"].DefaultView objPage.AllowPaging = True
objPage.PageSize = 2
Repeater1.DataSource = objPage
objPage.CurrentPageIndex = 1 Repeater1.DataBind()
End Using
End Sub
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "id")%>
<%#DataBinder.Eval(Container.DataItem, "biaoti")%>
<%#DataBinder.Eval(Container.DataItem, "biaoti")%>
</li>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
我是asp转.net的,很多控件都不太理解是怎么回事,帮忙看看怎么回事?
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace = "System.Data"%>
<%@ Import Namespace = "System.Data.Odbc"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Call show_list()
End Sub
Sub show_list()
Using connection As New OdbcConnection(ConfigurationSettings.AppSettings("ConnectionString"))
'创建SQL语句 Dim sql = "select * from wenzhang" Dim da As New OdbcDataAdapter(sql, connection) '创建DataSet对象
'DataSet(ds = New DataSet())
Dim ds As New DataSet da.Fill(ds, "wenzhang") '创建分页类
Dim objpage As New PagedDataSource
'PagedDataSource(objPage = New PagedDataSource()) '设置数据源
objpage.DataSource = ds.Tables
'objPage.DataSource=ds.Tables["authors"].DefaultView objPage.AllowPaging = True
objPage.PageSize = 2
Repeater1.DataSource = objPage
objPage.CurrentPageIndex = 1 Repeater1.DataBind()
End Using
End Sub
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "id")%>
<%#DataBinder.Eval(Container.DataItem, "biaoti")%>
<%#DataBinder.Eval(Container.DataItem, "biaoti")%>
</li>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
异常详细信息: System.InvalidCastException: 无法将类型为“System.Data.DataTable”的对象强制转换为类型“System.Collections.IEnumerable”。源错误:
行 29:
行 30: '设置数据源
行 31: objpage.DataSource = ds.Tables("wenzhang")
行 32: 'objPage.DataSource=ds.Tables["authors"].DefaultView
行 33:
源文件: D:\wwwroot\cccnc.net\fenye.aspx 行: 31
指定了表名就要把表名加上,一个DATASET可以包含多个表,如果你da.Fill(ds, "wenzhang")
的时候不指定表名,才可以用形如objpage.DataSource = ds的写法
------------------
我希望能接受查询条件,例如id=5的,
Dim sql = "select * from wenzhang where id = 5"
就又什么也不显示了,我该如何处理request.querrystring过来的sql过滤条件?
如果Request.QueryString为整型
Dim query = Request.QueryString("id");
然后判断query是否为null或者为空
再用正则判断是否为数字:
正则为:^[0-9]+$
如果是数字
Dim sql = "select * from wenzhang where id = " & query
由于我不会VB的语法,所以只能给你思路,你可以查看下相关文档