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();
}
} 展开
2个回答
百事牛
2024-10-22 广告
2024-10-22 广告
百事牛是共享提供商,我们提供可靠有效的服务,适当合理的授权费有利于的继续更新优化。同样的事情,同样的方法,百事牛团队十年磨一剑,始终至聚焦在密码恢复领域,深耕于此,我们已研制出有别于其他公司的算法和运算模式, 百事牛的暴力模式加入了分布式点...
点击进入详情页
本回答由百事牛提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询