我想知道表中的数量列是否有 NULL 值,如果它有 NULL 值,那么我想做一个操作,如果没有,那么我想做一些其他操作
有人可以帮我解决这个问题吗?
我试过这个代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string select = "select * from business where category_id=23 ";
scon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\bookdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
scon.Open();
DataTable table = new DataTable();
cmd = new SqlCommand(select, scon);
dr = cmd.ExecuteReader();
int count = 1;
while (dr.Read())
{
TableRow rnew = new TableRow();
Table1.Rows.Add(rnew);
TableCell cnew = new TableCell();
TableCell cnew1 = new TableCell();
Label lb1 = new Label();
lb1.Text = "(" + count.ToString() + ")<br/>";
Image img = new Image();
img.ImageUrl = dr["image_url"].ToString();
Label lb = new Label();
lb.Text = "Name:-" + dr["book_name"].ToString() + "<br/>";
lb.Text += "Author:-" + dr["author"].ToString() + "<br/>";
lb.Text += "price:-" + dr["price"].ToString() + "Rs.<br/><br/>";
lb.Text += dr["notes"].ToString() + "<br/><br/><br/>";
foreach(DataRow row in table.Rows)
{
object value = row["quantity"];
if (value == DBNull.Value)
LinkButton lbt = new LinkButton();
lbt.Text = "Order";
lbt.PostBackUrl = "~/orderlogin.aspx?itemid=" + dr["item_id"].ToString() + "&" + "catid=" + dr["category_id"].ToString();
lbt.visible=true;
else
lbt.visible=false;
}
cnew.Controls.Add(lb1);
cnew.Controls.Add(img);
cnew.Controls.Add(lbt);
cnew1.Controls.Add(lb);
rnew.Cells.Add(cnew);
rnew.Cells.Add(cnew1);
count++;
}
dr.Close();
scon.Close();
}
}
}