问题:从数据库中选出数据显示在示在一个gridview上
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Desktop_Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
if(Request.QueryString["Keyword"] != null)
{
Keyword.Text = Server.HtmlDecode(Request.QueryString["Keyword"].ToString());
}
}
}
protected void CommitBtn_Click(object sender,EventArgs e)
{
try
{
////实例化SqlConnection对象
//SqlConnection sqlCon = new SqlConnection();
////实例化SqlConnection对象连接数据库的字符串
//sqlCon.ConnectionString = "server=.;uid=sa;pwd=111111;database=xiaoxiao";
////定义SQL语句
//string SqlStr = "select * from tb where 商品名称='"+Keyword.Text +"'";
////实例化SqlDataAdapter对象
//SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
////实例化数据集DataSet
//DataSet ds = new DataSet();
//da.Fill(ds, "tb");
////绑定DataList控件
//this.GridView1.DataSource = ds;
//this.GridView1.DataBind();
////this.ProductView.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
////this.ProductView.DataBind();//将控件及其所有子控件绑定到指定的数据源
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("select * from tb where 商品名称='"+Keyword.Text.Trim() +"'",conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1 .DataSource =ds.
Gv.DataSource = ds.table[0].DefaultView;
Gv.DataBind();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
catch(System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
c
}
/////绑定控件的数据,显示搜索结果
//ProductView.DataSource = ds;
//ProductView.DataBind();
/////显示提示信息
//ProductView.Visible = ProductView.Rows.Count <= 0 ? false : true;
}
}
有谁可以帮忙修改一下瓦?谢谢啦~