一个C#的小问题
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 password : System.Web.UI.Page
{
private string strsql;
private string strconn;
private string str1, str2;
private SqlDataReader objdr;
private SqlCommand objcommand;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
strconn = "data source=127.0.0.1;database=工资管理系统;user id=jishen521;password=8053263;";
strsql = "select 员工编号,密码 from 用户表 where 员工编号='" + this.TextBox1.Text + "'";
strsql +="updata 用户表 set 密码 ='" + this.TextBox3.Text + "' where 员工编号 = '" + this.TextBox1.Text + "'";
SqlConnection myconn = new SqlConnection(strconn);
objcommand = new SqlCommand(strsql, myconn);
objcommand.Connection.Open();
//myconn.Open();
//objcommand.ExecuteNonQuery();
objdr = objcommand.ExecuteReader();
while(objdr.Read())
{
str1 = objdr.GetString(0);
str2 = objdr.GetString(1);
if(this.str2.Trim()!=this.TextBox2.Text.Trim())
{
this.Response.Write("<script language=javascript>alert('密码输入错误!')</script>");
}
}
}
}
显示如下错误:
“/工资管理系统”应用程序中的服务器错误。
--------------------------------------------------------------------------------
'updata' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 'updata' 附近有语法错误。
源错误:
行 31: //myconn.Open();
行 32: //objcommand.ExecuteNonQuery();
行 33: objdr = objcommand.ExecuteReader();
行 34:
行 35: while(objdr.Read())
--------------------编程问答-------------------- updata 改为 update --------------------编程问答-------------------- strsql = "select 员工编号,密码 from 用户表 where 员工编号='" + this.TextBox1.Text + "'";
strsql +="updata 用户表 set 密码 ='" + this.TextBox3.Text + "' where 员工编号 = '" + this.TextBox1.Text + "'";
问题就出在这儿了,你在这儿打个断点,看看你的strsql到底是什么? --------------------编程问答--------------------
人才啊
--------------------编程问答-------------------- 呵呵,顶下 --------------------编程问答--------------------
顶一下 --------------------编程问答--------------------
欠细心啊 --------------------编程问答--------------------
火眼金睛!! --------------------编程问答--------------------
没话说了 --------------------编程问答-------------------- updata改为update。以后出这种问题,可以把sql先贴到查询分析器里执行一下,看看是否能通过。不能通过的话,肯定是sql语句有问题。 --------------------编程问答-------------------- 语句一定要检查仔细啊,不然会很多麻烦 --------------------编程问答--------------------
+1 --------------------编程问答-------------------- 一个字母引发的惨剧...... --------------------编程问答-------------------- oh my god --------------------编程问答-------------------- updata 改为 update
--------------------编程问答-------------------- 你的updata改为update是应该的。
但是不明白,为什么你要把如下的sql语句连在一起?
strsql = "select 员工编号,密码 from 用户表 where 员工编号='" + this.TextBox1.Text + "'";
strsql +="updata 用户表 set 密码 ='" + this.TextBox3.Text + "' where 员工编号 = '" + this.TextBox1.Text + "'";
你的sql语句最后的结果应该是类似这个样子的:
select 员工编号,密码 from 用户表 where 员工编号='11'updata 用户表 set 密码 ='11' where 员工编号 = '11'
你觉得这样能执行吗? 放到数据库的查询工具里试试你的语句。 --------------------编程问答-------------------- 要学会自己调试! --------------------编程问答-------------------- +1 --------------------编程问答-------------------- ⊙﹏⊙b汗 --------------------编程问答-------------------- 不错啊 。。。。。
补充:.NET技术 , C#