asp.net linq用于显示信息 [英] asp.net linq for displayin information
本文介绍了asp.net linq用于显示信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class crudoperations : System.Web.UI.Page
{
inventoryDataContext obj = new inventoryDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
//displaying the product information based onn the entered by user with in textbox1
var result = from p in obj.products
where p.prodid=txtprodid.Text*************here iam getting the error******
select p;
if (result.Count() == 0)
Response.Write("<h1>no products</h1>");
else
{
foreach (var pp in result)
{
txtProddesc.Text = pp.proddesc;
txtPrice.Text = pp.price.ToString() ;
}
}
}
}
...
这里我得到一个错误不能隐式转换类型bool到字符串可以任何人帮助我,...如何纠正它
...
here iam getting an error cannot implicitly convert type bool to string can any one help me ,... how to rectify it
推荐答案
更正的代码
Corrected code
var result = from p in obj.products
where p.prodid==Convert.ToBoolean(txtprodid.Text.Trim())//Corrected here
select p;
在这里使用复选框而不是文本框
Use a checkbox instead of a textbox here
引用:
txtprodid.Text.Trim()
txtprodid.Text.Trim()
var result = from p in obj.products
where p.prodid=txtprodid.Text*************here iam getting the error******
select p;
需要:
Needs to be:
var result = from p in obj.products
where p.prodid==txtprodid.Text
select p;
注意==是平等...
Notice the == is equality...
这篇关于asp.net linq用于显示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文