ASP.Net和数据访问 [英] ASP.Net and Data access

查看:49
本文介绍了ASP.Net和数据访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去在ASP中开发过,现在正在进入ASP.Net并且已经打了一个路障。我一直在阅读tutorias和文件,但仍然有问题。我有以下代码示例:


******************************* *********


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase。加载

Dim DS As DataSet

Dim MyConnection As SqlConnection

Dim MyCommand As SqlDataAdapter


MyConnection =新的
SqlConnection(" server = sqlserver; database = sales; Tru sted_Connection = Yes")

MyCommand = New SqlDataAdapter(" select * from orders where orderid =

32000",MyConnection)


DS =新数据集

MyCommand.Fill(DS," Orders")


Repeater2.DataSource = DS

Repeater2.DataBind()

结束子


<%@ Page Language =" vb" AutoEventWireup = QUOT假QUOT; Codebehind =" orders.aspx.vb"%>

< HTML>

< HEAD>

< title> orders< ; / title>

< / HEAD>

< body>

< form runat =" server">

< asp:Repeater id =" Repeater2" runat =" server">

< HeaderTemplate>

< Table width =" 100%" style =" font:8pt verdana">


< tr>

< th>

订单ID

< / th>

< / tr>

< / HeaderTemplate>

< ItemTemplate>

< tr>

< td>

<%#DataBinder.Eval(Container.DataItem," OrderID")% >

< / td>

< / tr>

< / ItemTemplate>

< ; FooterTemplate>

< / table>

< / FooterTemplate>

< / asp:Repeater>< / TD>

< / form>

< / body>

< / HTML>


********** <无线电通信/>
这段代码看起来不错,但是当我运行它时,我在

页面上没有任何结果(空白)。这是我运行后的HTML:

< HTML>

< HEAD>

< title> orders< / title>

< / HEAD>

< body>

< form name =" _ctl0"方法= QUOT;交"行动= QUOT; orders.aspx" id =" _ctl0">

< input type =" hidden" name =" __ VIEWSTATE"

value =" dDw1NzE5OTAzNTI7Oz6dpCg + ix9Yj9gsw5NbtgI82h5 suw ==" />


< / TD>

< / form>

< / body>

< / HTML>

我无法理解为什么我没有收到任何数据。


任何帮助都会非常感激。

解决方案

尝试将DataSource设置为数据集中的Orders表,而不是

数据集对象本身。


" Paul"写道:

我过去在ASP中开发过,现在正在进入ASP.Net并且已经遇到了障碍。我一直在阅读tutorias和文件,但仍然有问题。我有以下代码示例:

*********************************** *****

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(" server = sqlserver; database = sales; Tru sted_Connection = Yes")
MyCommand = New SqlDataAdapter(select * from orders where orderid =
32000,MyConnection)

DS = New DataSet
MyCommand.Fill(DS,Orders)

Repeater2.DataSource = DS
Repeater2.DataBind()

End Sub

<%@ Page Language =" vb" ; AutoEventWireup = QUOT假QUOT; Codebehind =" orders.aspx.vb"%>
< HTML>
< HEAD>
< title>订单< / title>
< / HEAD> ;
< body>
< form runat =" server">
< asp:Repeater id =" Repeater2" runat =" server">
< HeaderTemplate>
< Table width =" 100%" style =" font:8pt verdana">

< tr>
< th>
订单ID
< / th>
< / tr>
< / HeaderTemplate>
< ItemTemplate>
< tr>
< td>
<%#DataBinder.Eval( Container.DataItem," OrderID")%>
< / td>
< / tr>
< / ItemTemplate>
< FooterTemplate>
< / table>
< / FooterTemplate>
< / asp:Repeater>< / TD>
< / form>
< / body>
< / HTML>

********************************** **************

这段代码看起来不错,但是当我运行这个代码时,我在
页面上没有任何内容(空白)。以下是我运行后的HTML:

< HTML>
< HEAD>
< title>订单< / title>
< / HEAD> ;
< body>
< form name =" _ctl0"方法= QUOT;交"行动= QUOT; orders.aspx" id =" _ctl0">
< input type =" hidden" name =" __ VIEWSTATE"
value =" dDw1NzE5OTAzNTI7Oz6dpCg + ix9Yj9gsw5NbtgI82h5 suw ==" />

< / TD>
< / form>
< / body>
< / HTML>

我只是无法理解为什么我没有得到任何数据。

任何帮助将不胜感激。



是否有orderid这个字段有

,orderID值为32000?


这就是你要求的。


如果记录的值为32000,则为在orderID

字段中不存在,没有什么可以显示。


Juan T. Llibre

ASP.NET MVP

===========

" Paul" <帕** @ discussions.microsoft.com>在消息中写道

新闻:A9 ********************************** @ microsof t.com ...

我过去在ASP中开发过,现在正在进入ASP.Net并且
已经遇到了障碍。我一直在阅读tutorias和文件,但仍然有问题。我有以下代码示例:

*********************************** *****

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(" server = sqlserver; database = sales; Tru sted_Connection = Yes")
MyCommand = New SqlDataAdapter(" select * from orders where orderid
=
32000",MyConnection)

DS =新数据集
MyCommand.Fill(DS,& ;订单")

Repeater2.DataSource = DS
Repeater2.DataBind()

End Sub

<%@ Page Language = QUOT; VB" AutoEventWireup =" false"
Codebehind =" orders.aspx.vb"%>
< HTML>
< HEAD>
< title> orders< / title>
< / HEAD>
< body>
< form runat =" server">
< asp:Repeater id =" Repeater2" runat =" server">
< HeaderTemplate>
< Table width =" 100%" style =" font:8pt verdana">

< tr>
< th>
订单ID
< / th>
< / tr>
< / HeaderTemplate>
< ItemTemplate>
< tr>
< td>
<%#DataBinder.Eval( Container.DataItem," OrderID")%>
< / td>
< / tr>
< / ItemTemplate>
< FooterTemplate>
< / table>
< / FooterTemplate>
< / asp:Repeater>< / TD>
< / form>
< / body>
< / HTML>

********************************** **************

这段代码看起来不错,但是当我运行这个代码时,我没有得到任何关于
的页面(空白)。以下是我运行后的HTML:

< HTML>
< HEAD>
< title>订单< / title>
< / HEAD> ;
< body>
< form name =" _ctl0"方法= QUOT;交"行动= QUOT; orders.aspx" id =" _ctl0">
< input type =" hidden" name =" __ VIEWSTATE"
value =" dDw1NzE5OTAzNTI7Oz6dpCg + ix9Yj9gsw5NbtgI82h5 suw ==" />

< / TD>
< / form>
< / body>
< / HTML>

我只是无法理解为什么我没有得到任何数据。

任何帮助将不胜感激。



这只是一个例子。我也想要检索其他一些领域但是

我什么都没得到。该记录确实存在于数据库中。


Juan T. Llibre写道:

是否有orderid订单ID值为32000的字段?

这就是您要求的内容。

如果一个值为32000的记录。在orderID
字段中不存在,没有什么可显示的。


Juan T. Llibre
ASP.NET MVP
===========
保罗 <帕** @ discussions.microsoft.com>在消息中写道
新闻:A9 ********************************** @ microsof t.com。 ..

我过去在ASP中开发过,现在正在进入ASP.Net并且
已经遇到了障碍。我一直在阅读tutorias和文件,但仍然有问题。我有以下代码示例:

*********************************** *****

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(" server = sqlserver; database = sales; Tru sted_Connection = Yes")
MyCommand = New SqlDataAdapter(" select * from orders where orderid
=
32000",MyConnection)

DS =新数据集
MyCommand.Fill(DS,& ;订单")

Repeater2.DataSource = DS
Repeater2.DataBind()

End Sub

<%@ Page Language = QUOT; VB" AutoEventWireup =" false"
Codebehind =" orders.aspx.vb"%>
< HTML>
< HEAD>
< title> orders< / title>
< / HEAD>
< body>
< form runat =" server">
< asp:Repeater id =" Repeater2" runat =" server">
< HeaderTemplate>
< Table width =" 100%" style =" font:8pt verdana">

< tr>
< th>
订单ID
< / th>
< / tr>
< / HeaderTemplate>
< ItemTemplate>
< tr>
< td>
<%#DataBinder.Eval( Container.DataItem," OrderID")%>
< / td>
< / tr>
< / ItemTemplate>
< FooterTemplate>
< / table>
< / FooterTemplate>
< / asp:Repeater>< / TD>
< / form>
< / body>
< / HTML>

********************************** **************

这段代码看起来不错,但是当我运行这个代码时,我没有得到任何关于
的页面(空白)。以下是我运行后的HTML:

< HTML>
< HEAD>
< title>订单< / title>
< / HEAD> ;
< body>
< form name =" _ctl0"方法= QUOT;交"行动= QUOT; orders.aspx" id =" _ctl0">
< input type =" hidden" name =" __ VIEWSTATE"
value =" dDw1NzE5OTAzNTI7Oz6dpCg + ix9Yj9gsw5NbtgI82h5 suw ==" />

< / TD>
< / form>
< / body>
< / HTML>

我只是无法理解为什么我没有得到任何数据。

任何帮助都将不胜感激。




I have developed in ASP in the past and am now getting into ASP.Net and have
hit a road block. I''ve been reading tutorias and documents and am still
having problems. I have the following code example:

****************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=sqlserver;database=sales;Tru sted_Connection=Yes")
MyCommand = New SqlDataAdapter("select * from orders where orderid =
32000", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater2.DataSource = DS
Repeater2.DataBind()
End Sub

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="orders.aspx.vb"%>
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">

<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>

************************************************
This code looks good to me but when I run this, I do not get anything on the
page (blank). Here is the html after I run it:
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form name="_ctl0" method="post" action="orders.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="dDw1NzE5OTAzNTI7Oz6dpCg+ix9Yj9gsw5NbtgI82h5 suw==" />

</TD>
</form>
</body>
</HTML>
I just cant understand why I am not getting any data.

Any help would be much appreciated.

解决方案

Try setting the DataSource to the Orders Table in the dataset instead of the
dataset object itself.

"Paul" wrote:

I have developed in ASP in the past and am now getting into ASP.Net and have
hit a road block. I''ve been reading tutorias and documents and am still
having problems. I have the following code example:

****************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=sqlserver;database=sales;Tru sted_Connection=Yes")
MyCommand = New SqlDataAdapter("select * from orders where orderid =
32000", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater2.DataSource = DS
Repeater2.DataBind()
End Sub

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="orders.aspx.vb"%>
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">

<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>

************************************************
This code looks good to me but when I run this, I do not get anything on the
page (blank). Here is the html after I run it:
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form name="_ctl0" method="post" action="orders.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="dDw1NzE5OTAzNTI7Oz6dpCg+ix9Yj9gsw5NbtgI82h5 suw==" />

</TD>
</form>
</body>
</HTML>
I just cant understand why I am not getting any data.

Any help would be much appreciated.



Is there an "orderid" field which has
an orderID value of 32000 ?

That''s what you''re requesting.

If a record with the value "32000" in the "orderID"
field doesn''t exist, there''s nothing to display.


Juan T. Llibre
ASP.NET MVP
===========
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...

I have developed in ASP in the past and am now getting into ASP.Net and
have
hit a road block. I''ve been reading tutorias and documents and am still
having problems. I have the following code example:

****************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=sqlserver;database=sales;Tru sted_Connection=Yes")
MyCommand = New SqlDataAdapter("select * from orders where orderid
=
32000", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater2.DataSource = DS
Repeater2.DataBind()
End Sub

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="orders.aspx.vb"%>
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">

<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>

************************************************
This code looks good to me but when I run this, I do not get anything on
the
page (blank). Here is the html after I run it:
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form name="_ctl0" method="post" action="orders.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="dDw1NzE5OTAzNTI7Oz6dpCg+ix9Yj9gsw5NbtgI82h5 suw==" />

</TD>
</form>
</body>
</HTML>
I just cant understand why I am not getting any data.

Any help would be much appreciated.



This was just an example. I was tring to retrieve some other fields also but
I still get nothing. This record does exist in the database.

"Juan T. Llibre" wrote:

Is there an "orderid" field which has
an orderID value of 32000 ?

That''s what you''re requesting.

If a record with the value "32000" in the "orderID"
field doesn''t exist, there''s nothing to display.


Juan T. Llibre
ASP.NET MVP
===========
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...

I have developed in ASP in the past and am now getting into ASP.Net and
have
hit a road block. I''ve been reading tutorias and documents and am still
having problems. I have the following code example:

****************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=sqlserver;database=sales;Tru sted_Connection=Yes")
MyCommand = New SqlDataAdapter("select * from orders where orderid
=
32000", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater2.DataSource = DS
Repeater2.DataBind()
End Sub

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="orders.aspx.vb"%>
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">

<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>

************************************************
This code looks good to me but when I run this, I do not get anything on
the
page (blank). Here is the html after I run it:
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form name="_ctl0" method="post" action="orders.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="dDw1NzE5OTAzNTI7Oz6dpCg+ix9Yj9gsw5NbtgI82h5 suw==" />

</TD>
</form>
</body>
</HTML>
I just cant understand why I am not getting any data.

Any help would be much appreciated.




这篇关于ASP.Net和数据访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆