public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
this.bind();
}
} public SqlConnection GetConnection()
{
string mystr = ConfigurationManager.ConnectionStrings["db_09ConnectionString"].ConnectionString;
SqlConnection myconn =new SqlConnection(mystr) ; return myconn;
} public void bind()
{
SqlConnection myconn = GetConnection();
myconn.Open();
string strSql = "select * from tb_Student";
SqlDataAdapter myDa = new SqlDataAdapter(strSql, myconn);
DataSet myDs =new DataSet();
myDa.Fill(myDs);
GridView1.DataSource=myDs;
GridView1 .DataBind ();
myDa .Dispose();
myDs .Dispose();
myconn.Dispose();
}
protected void btnSelect_Click(object sender, EventArgs e)
{ if (this.txtName.Text !="")
{
SqlConnection myconn = GetConnection(); myconn.Open();
string sqlStr = "select * from tb_Student wherer Name =@Name";
SqlCommand myCmd = new SqlCommand(sqlStr,myconn); myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim();
//myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim();
//myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim(); SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
if (myDs.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = myDs;
GridView1.DataBind(); } else
{
Response.Write("<script>alert ('没有相关记录')</script>");
}
myDa.Dispose();
myDs.Dispose();
myconn.Dispose(); } else this.bind(); }
}//错误显示在 : myDa.Fill(myDs); 用户代码未处理sqlexception, 'Name' 附近有语法错误。谢谢
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
this.bind();
}
} public SqlConnection GetConnection()
{
string mystr = ConfigurationManager.ConnectionStrings["db_09ConnectionString"].ConnectionString;
SqlConnection myconn =new SqlConnection(mystr) ; return myconn;
} public void bind()
{
SqlConnection myconn = GetConnection();
myconn.Open();
string strSql = "select * from tb_Student";
SqlDataAdapter myDa = new SqlDataAdapter(strSql, myconn);
DataSet myDs =new DataSet();
myDa.Fill(myDs);
GridView1.DataSource=myDs;
GridView1 .DataBind ();
myDa .Dispose();
myDs .Dispose();
myconn.Dispose();
}
protected void btnSelect_Click(object sender, EventArgs e)
{ if (this.txtName.Text !="")
{
SqlConnection myconn = GetConnection(); myconn.Open();
string sqlStr = "select * from tb_Student wherer Name =@Name";
SqlCommand myCmd = new SqlCommand(sqlStr,myconn); myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim();
//myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim();
//myCmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = this.txtName.Text.Trim(); SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
if (myDs.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = myDs;
GridView1.DataBind(); } else
{
Response.Write("<script>alert ('没有相关记录')</script>");
}
myDa.Dispose();
myDs.Dispose();
myconn.Dispose(); } else this.bind(); }
}//错误显示在 : myDa.Fill(myDs); 用户代码未处理sqlexception, 'Name' 附近有语法错误。谢谢
where 写错了
where写错了
Name 关键字
把wherer改成where就行了
第二、将wherer写成where。
where 写错了
select * from tb_Student where ......
-_________-!!!
sql语句错了,你实在发现不了错误的话,就将sql语句在查询分析器里运行一下,运行无误了,再写到程序里