ASP.NET中存储db值的问题 [英] Problem in ASP.NET to store db values
本文介绍了ASP.NET中存储db值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SQl中占了一张桌子floor
哪些列像''id''
自动生成和''name''
。在那里我插入3个值,如一个,两个,三个。
我的问题是;
i想要读取数据库中的3个值并显示与3个值相关的3个图像。
我的代码是这样的。
Hi,
I have take one table in SQl "floor"
which columns like ''id''
autogenerated and ''name''
. And in that i insert 3 values like "one","two","three".
My question is ;
i want to read that 3 values from database and related to that three values disply 3 images.
My code like this.
string str;
con.Open();
cmd = new SqlCommand("Select name from floor",con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
str = Convert.ToString(dr["name"].ToString());
if (str == "one" && str=="two" && str=="three")
{
Image1.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_101_booked.png";
Image2.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_102.png";
Image3.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_103.png";
}
}
con.Close();
但我不明白如果条件如何使用。
求助。我在等。
But I am not understand how to use that if condition.
Pleases help. I am waiting.
推荐答案
你的逻辑语句永远不会是真的....
str变量只能是其中一个值所有这三个。
your logical statement will never be true....
str variable can only be one of the values not all three of them.
if (str == "one" && str=="two" && str=="three")
你可能想要的是
what you probably want is
if (str == "one")
Image1.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_101_booked.png";
else if (str == "two")
Image2.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_102.png";
else if (str == "three")
Image3.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_103.png";
或者这个
Or this
if (str == "one" || str=="two" || str== "three")
{
Image1.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_101_booked.png";
Image2.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_102.png";
Image3.ImageUrl = "~/images/book_flat_imgs/AWing/first_floor/A_103.png";
}
通常会读取c#运算符和逻辑运算符以了解您的代码正在做什么。
http://msdn.microsoft.com/en-us/library/6a71f45d(v=vs .71).aspx [ ^ ]
这篇关于ASP.NET中存储db值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文