在aspx和cs中显示字段 [英] Displaying Fields in aspx and cs

查看:64
本文介绍了在aspx和cs中显示字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚开始围绕C Sharp和aspx工作。


用于在asp中编写我的所有网站,只需要一些指示如何

显示数据。


我用SqlConnection建立了与SQL2000数据库的连接,因为我认为这是最快最好的吗? />

我也编写了我的SELECT语句,但我很困惑如何显示

这些数据不在表中,因为网络上的所有示例似乎都要我

do!


在过去,我会使用

<%Response.Write(Rs.Fields( fld_field_1)。值)%>


我现在使用类似


< asp:label id = fld_field_1 runat =" server" />


我是否需要在代码顶部添加一些内容才能使用它?


谢谢!

解决方案




有很多方法。

你可以用一个Dataadapter用于填充数据集,您可以将其设置为数据网格的

数据源。

您还可以使用数据加载器从SQL读取数据。

// DataReader示例

SqlConnection SqlCon = new SqlConnection();

SqlCommand SqlCom = new SqlCommand();

SqlDataReader SqlDr;

SqlCom.Connection = SqlCon;

SqlCom.Commandtext =" select * from table" ;;

SqlCon.Open();

SqlDr = SqlCom.ExecuteReader();

while(SqlDr.Read())

{

SqlDr [" NameOfRow"]。toString();

SqlDr [IndexOfRowAsInt] .toString();

SqlDr.Getxxxxxxx //看一下SqlDataReader你可以做什么

it

}

SqlDr.Close();

SqlCon.Close();


希望这会有所帮助。

cu

Bjoern Wolfgardt


" Charles Astwood" < BA ******** @ nospam.hotmail.com> schrieb im Newsbeitrag

新闻:bg ********** @ sparta.btinternet.com ...

刚开始以我的方式工作C Sharp和aspx。

用于在asp中编写我的所有网站,只需要一些关于如何显示数据的指示。

我已建立连接用我的SQL2000数据库和SqlConnection一样,我认为这是最快最好的吗?

我也编写了我的SELECT语句,但我很困惑如何显示这个数据而不是在表中,因为网上的所有例子似乎都要我这样做!

在过去,我会使用
<%Response.Write(Rs。字段(fld_field_1)。值)%>

我现在使用类似

< asp:label id = fld_field_1 runat =" server" / >

我是否需要在代码顶部放置一些内容才能使用它?

谢谢!






有很多方式。

您可以使用Dataadapter填充数据集,您可以将其设置为数据网格的

数据源。

您也可以使用用于从SQL读取数据的datareader。

// DataReader示例

SqlConnection SqlCon = new SqlConnection();

SqlCommand SqlCom = new SqlCommand( );

SqlDataReader SqlDr;

SqlCom.Connection = SqlCon;

SqlCom.Commandtext =" select * from table" ;;

SqlCon.Open();

SqlDr = SqlCom.ExecuteReader();

while(SqlDr.Read())

{

SqlDr [" NameOfRow"]。toString();

SqlDr [IndexOfRowAsInt] .toString();

SqlDr.Getxxxxxxx //看看SqlDataReader你可以做什么



}

SqlDr.Close();

SqlCon.Close();


希望这会有所帮助。

cu

Bjoern Wolfgardt


" Charles Astwood" < BA ******** @ nospam.hotmail.com> schrieb im Newsbeitrag

新闻:bg ********** @ sparta.btinternet.com ...

刚开始以我的方式工作C Sharp和aspx。

用于在asp中编写我的所有网站,只需要一些关于如何显示数据的指示。

我已建立连接用我的SQL2000数据库和SqlConnection一样,我认为这是最快最好的吗?

我也编写了我的SELECT语句,但我很困惑如何显示这个数据而不是在表中,因为网上的所有例子似乎都要我这样做!

在过去,我会使用
<%Response.Write(Rs。字段(fld_field_1)。值)%>

我现在使用类似

< asp:label id = fld_field_1 runat =" server" / >

我是否需要在代码顶部放置一些内容才能使用它?

谢谢!






我忘了电话l你如何显示数据。

你可以使用''old''方式:Response.Write(SqlDr [" NameOfRow"]。toString());

或者你可以使用这样的东西。


this.textbox1.text = SqlDr [" NameOfRow"]。toString();


cu

Bjoern Wolfgardt

" Charles Astwood" < BA ******** @ nospam.hotmail.com> schrieb im Newsbeitrag

新闻:bg ********** @ sparta.btinternet.com ...

刚开始以我的方式工作C Sharp和aspx。

用于在asp中编写我的所有网站,只需要一些关于如何显示数据的指示。

我已建立连接用我的SQL2000数据库和SqlConnection一样,我认为这是最快最好的吗?

我也编写了我的SELECT语句,但我很困惑如何显示这个数据而不是在表中,因为网上的所有例子似乎都要我这样做!

在过去,我会使用
<%Response.Write(Rs。字段(fld_field_1)。值)%>

我现在使用类似

< asp:label id = fld_field_1 runat =" server" / >

我是否需要在代码顶部放置一些内容才能使用它?

谢谢!



Hi, just starting out working my way round C Sharp and aspx.

Used to write all my sites in asp and just need a few pointers in how to
display data.

I have made a connection to my SQL2000 database with SqlConnection as I
think this is the fastest and best?

I have also written my SELECT statement, but am confused in how to display
this data not in a Table as all the examples on the web seem to want me to
do!

In the old days I would have used
<%Response.Write (Rs.Fields("fld_field_1").value)%>

Do I now use something like

<asp:label id=fld_field_1 runat="server"/>

and do I need to put something at the top of the code to use this?

Thanks!

解决方案

Hi,

there are many ways.
You can use a Dataadapter to fill a dataset which you can set as the
datasource for a datagrid.
You can also use a datareader to read data from SQL.
// DataReader Example
SqlConnection SqlCon = new SqlConnection();
SqlCommand SqlCom = new SqlCommand();
SqlDataReader SqlDr;
SqlCom.Connection = SqlCon;
SqlCom.Commandtext = "select * from table";
SqlCon.Open();
SqlDr = SqlCom.ExecuteReader();
while(SqlDr.Read())
{
SqlDr["NameOfRow"].toString();
SqlDr[IndexOfRowAsInt].toString();
SqlDr.Getxxxxxxx // Take a look at the SqlDataReader what you can do with
it
}
SqlDr.Close();
SqlCon.Close();

hope this helps a bit.
cu
Bjoern Wolfgardt

"Charles Astwood" <ba********@nospam.hotmail.com> schrieb im Newsbeitrag
news:bg**********@sparta.btinternet.com...

Hi, just starting out working my way round C Sharp and aspx.

Used to write all my sites in asp and just need a few pointers in how to
display data.

I have made a connection to my SQL2000 database with SqlConnection as I
think this is the fastest and best?

I have also written my SELECT statement, but am confused in how to display
this data not in a Table as all the examples on the web seem to want me to
do!

In the old days I would have used
<%Response.Write (Rs.Fields("fld_field_1").value)%>

Do I now use something like

<asp:label id=fld_field_1 runat="server"/>

and do I need to put something at the top of the code to use this?

Thanks!



Hi,

there are many ways.
You can use a Dataadapter to fill a dataset which you can set as the
datasource for a datagrid.
You can also use a datareader to read data from SQL.
// DataReader Example
SqlConnection SqlCon = new SqlConnection();
SqlCommand SqlCom = new SqlCommand();
SqlDataReader SqlDr;
SqlCom.Connection = SqlCon;
SqlCom.Commandtext = "select * from table";
SqlCon.Open();
SqlDr = SqlCom.ExecuteReader();
while(SqlDr.Read())
{
SqlDr["NameOfRow"].toString();
SqlDr[IndexOfRowAsInt].toString();
SqlDr.Getxxxxxxx // Take a look at the SqlDataReader what you can do with
it
}
SqlDr.Close();
SqlCon.Close();

hope this helps a bit.
cu
Bjoern Wolfgardt

"Charles Astwood" <ba********@nospam.hotmail.com> schrieb im Newsbeitrag
news:bg**********@sparta.btinternet.com...

Hi, just starting out working my way round C Sharp and aspx.

Used to write all my sites in asp and just need a few pointers in how to
display data.

I have made a connection to my SQL2000 database with SqlConnection as I
think this is the fastest and best?

I have also written my SELECT statement, but am confused in how to display
this data not in a Table as all the examples on the web seem to want me to
do!

In the old days I would have used
<%Response.Write (Rs.Fields("fld_field_1").value)%>

Do I now use something like

<asp:label id=fld_field_1 runat="server"/>

and do I need to put something at the top of the code to use this?

Thanks!



Hi,

I forgot to tell you how to display the data.
You can use the ''old'' way : Response.Write(SqlDr["NameOfRow"].toString());
Or you can use something like this.

this.textbox1.text = SqlDr["NameOfRow"].toString();

cu
Bjoern Wolfgardt
"Charles Astwood" <ba********@nospam.hotmail.com> schrieb im Newsbeitrag
news:bg**********@sparta.btinternet.com...

Hi, just starting out working my way round C Sharp and aspx.

Used to write all my sites in asp and just need a few pointers in how to
display data.

I have made a connection to my SQL2000 database with SqlConnection as I
think this is the fastest and best?

I have also written my SELECT statement, but am confused in how to display
this data not in a Table as all the examples on the web seem to want me to
do!

In the old days I would have used
<%Response.Write (Rs.Fields("fld_field_1").value)%>

Do I now use something like

<asp:label id=fld_field_1 runat="server"/>

and do I need to put something at the top of the code to use this?

Thanks!



这篇关于在aspx和cs中显示字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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