求高手解答 如何查询到更多的商品!

代码如下,现在怎么弄都只能显示一条商品信息,想查更多不同商品并显示在gridview
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Collections;
public partial class pos : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
GetUserInfo("SELECT Code,Goodsname,price FROM goods where Code = " + TextBox2.Text + "");
}
private void GetUserInfo(string strcmd) //使用方法对Gridview填充查询到的数据,前台属性设置AutoGenerateColumns="false" 即可开启需要显示的列
{
SqlConnection conn = new SqlConnection(rvshiconn.sqlconn);
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(strcmd, conn);
DataSet ds = new DataSet();
da.Fill(ds, "goods");
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
Label1.Text = ds.Tables[0].Compute("Sum(price)", "true").ToString(); ;
}
catch (SqlException ex)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "alere('" + ex.Message + "')");
}
finally
{
conn.Close();
}
}
}

1个回答

GetUserInfo("SELECT Code,Goodsname,price FROM goods where Code = " + TextBox2.Text + "");
去掉where看看

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!