用C#.net在WEB上实现一个搜索功能

来源:百度知道 编辑:UC知道 时间:2024/06/14 00:54:09
一个名为Student的表,表里包括Num,Name,Sex,Info,再从TextBox里输入一个字段搜索出全部信息,再用GridView显示出来

楼上错了 首先 WEB里没有DataGridView 应该是GridView
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
txtCurrent.Text = Session["Current"].ToString();
txtTotal.Text = Application["Total"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string strSql = "select * from Student where Num=" + Int32.Parse(txt.Text);
GridView1.DataSource = ds;
GridView1.DataBind();
}
public DataSet getbind(string strSql)
{
conn = new SqlConnection("server=(Loval);uid=youname;pwd=youpassword;database=youDB");
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSql);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
}
刚给你