[英]Retrieve integer value from database
I would like to know how to get an Integer
value from a database and put it into a TextBox
.我想知道如何从数据库中获取
Integer
值并将其放入TextBox
。
I know how to get a VARCHAR
value from a database, which looks like this:我知道如何从数据库中获取
VARCHAR
值,如下所示:
public static string email;
public static string Email
{
get { return email; }
set { email = value; }
}
Then, at the database code:然后,在数据库代码处:
if (dr.Read())
{
Email = dr["email"].ToString();
}
But how do I retrieve an int
?但是如何检索
int
?
You can use:您可以使用:
var result = dr.Field<int?>("intCol");
txtField.Text = result;
You should not use static
for your model class.你不应该为你的模型类使用
static
。
public class YourModel
{
public string Email { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.