无法绑定由多个部分组成的标识符 "txtmodel.Text"。

来源:百度知道 编辑:UC知道 时间:2024/05/14 11:35:50
protected void Page_Load(object sender, EventArgs e)
{
txtmodel.Text = Request.QueryString["bid"].ToString();
string strconn = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection con = new SqlConnection(strconn);
string sql1 = "select proname,promodel,prospec,producer,unitprice,danwei,prodesc from jichuang where [promodel]=txtmodel.Text";
SqlCommand cmd = new SqlCommand(sql1, con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables[0];
string bn = dt.Rows[0]["promodel"].ToString();
Response.Write(bn);
con.Close();
}

如果是数字:
string sql1 = "select proname,promodel,prospec,producer,unitprice,danwei,prodesc from jichuang where [promodel]="+txtmodel.Text;
如果是字符串:
string sql1 = "select proname,promodel,prospec,producer,unitprice,danwei,prodesc from jichuang where [promodel]='"+txtmodel.Text+"'";

另外,这样拼接查询字符串,得考虑到sql 注入的风险