你每一次submit时,都插入了数据,你的写法有问题
if(dt.Rows.Count>0)
{
if((dt.Rows[0]["length"].ToString()).Trim()==len.Text&&(dt.Rows[0]"width"].ToString()).Trim()==wid.Text)
{
Session["id"]=(object)(dt.Rows[0]["productid"].ToString().Trim());
Response.Redirect("order1.aspx");
}
else {
Bind();
}
}
if(dt.Rows.Count>0)
{
if((dt.Rows[0]["length"].ToString()).Trim()==len.Text&&(dt.Rows[0]"width"].ToString()).Trim()==wid.Text)
{
Session["id"]=(object)(dt.Rows[0]["productid"].ToString().Trim());
Response.Redirect("order1.aspx");
}
else {
Bind();
}
}
此句有问题,应该为
SqlDataAdapter myCommand=new SqlDataAdapter("select * from pro where radio='"+radior.Text+"' and length='"+len.Text+"' and width='"+wid.Text+"'",myConnection);
private void submit_Click(object sender, System.EventArgs e)
{
{
SqlConnection myConnection=new SqlConnection("uid=sa;pwd=pass;initial catalog=as");
SqlDataAdapter myCommand=new SqlDataAdapter("select * from pro where radio='"+radior.Text+"' and length='"+len.Text+"' and width='"+wid.Text+"'",myConnection);
DataSet ds=new DataSet();
myCommand.Fill(ds,"ss");
DataTable dt=ds.Tables["ss"];
if(dt.Rows.Count>0)
{
Session["id"]=(object)(dt.Rows[0]["productid"].ToString().Trim());
Response.Redirect("order1.aspx");
}
else
Bind();
}
}
非常感谢,问题解决了。顺便问一下,有没有更简单一点的办法来检索数据,如果选择项很多,select 语句不是要写很长吗?