我如何使用eval在asp.net中读取从数据库中的字段? [英] How can I use Eval in asp.net to read fields from a database?

查看:113
本文介绍了我如何使用eval在asp.net中读取从数据库中的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的情况是:

我有一个需要从使用eval函数在.aspx页面数据库中读取特定字段一个WebForm。我知道如何在.aspx页面中指定的值,但在后面,我怎么搞定的值,并将其绑定到.aspx页面中的code?我可以只用一个DataReader?数据集?究竟我该怎么具有约束力或读取的数据集或阅读器?我需要创建一个方法?

I have a webform that needs to read specific fields from a database that uses the eval function in the .aspx page. I know how to assign the values in the .aspx page, but in the code behind how do I "get" the values and bind them to the .aspx page? Can I just used a datareader? Dataset? What exactly am I going to be binding or reading to the dataset or reader? Do I need to create a method?

我已经创建从数据库中提取数据的存储过程。我要创建存储过程的方法。我只是不创造哪种...数据集,DataReader的?我如何code将其背后的code?

I already have the stored procedure created to pull the data from the database. I was going to create a method with the stored procedure. I just dont which kind to create...dataset, datareader? And how do I code it in the code behind?

推荐答案

声明公共属性为您的数据库字段:

Declare public properties for your DB fields:

public int MyFieldID = 0;
public string MyStringFromDB = string.empty;

// PAGE LOAD GET DB VALUES
{
    MyFieldID = Convert.ToInt32(db["ID"]);
    MyStringFromDB = Convert.ToString(db["FIELD"]);
}

现在,你可以只为它们分配在aspx页面像<%= MyFieldID%>或code后面使用它们

Now you can either just assign them in the aspx page like <%=MyFieldID%> or use them in the code behind.

这篇关于我如何使用eval在asp.net中读取从数据库中的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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