ASP.net中,通过文本框输入值来查询数据库,我的代码哪里错了?
publicpartialclassCPinformation:System.Web.UI.Page{DataSetGetDataSet(stringname){SqlC...
public partial class CPinformation : System.Web.UI.Page
{
DataSet GetDataSet(string name) {
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data source=YC-PC; Initial Catalog=餐厅管理系统表;Integrated Security=True";
mycon.Open();
SqlCommand selectCMD = new SqlCommand("select code from CPxx where code='" + TextBox1.Text.Trim() + "'", mycon);
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "CPxx");
mycon.Close();
return custDS;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text.ToString();
DataSet ds = GetDataSet(name);
GridView1.DataSource = ds.Tables["CPxx"];
GridView1.DataBind();
}
} 展开
{
DataSet GetDataSet(string name) {
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data source=YC-PC; Initial Catalog=餐厅管理系统表;Integrated Security=True";
mycon.Open();
SqlCommand selectCMD = new SqlCommand("select code from CPxx where code='" + TextBox1.Text.Trim() + "'", mycon);
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "CPxx");
mycon.Close();
return custDS;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text.ToString();
DataSet ds = GetDataSet(name);
GridView1.DataSource = ds.Tables["CPxx"];
GridView1.DataBind();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询