急急急急急急急急急急急 sql语句错了?

QQ12236822 2009-03-11 12:17:52
 string updatacmd = "update g_user set name='" + txt_name.Text + "',card='" + txt_card.Text + "',riqi='" + txt_money.Text + "',gtel='" + txt_gtel.Text + "',tel='" + txt_tel.Text + "',email='" + txt_email.Text + "',youbian='" + txt_youbian.Text + "',address='" + txt_add.Text + "',sex='" + txt_sex.Text + "',danbaoren='" + txt_danbaoren.Text + "', job='" + txt_joy.Text + "' where id='" + txt_serch.Text + "'";
...全文
185 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzxap 2009-03-11
  • 打赏
  • 举报
回复
job='"+txt_job.text+"'
错写成job='"+txt_joy.text+"'

小心点
QQ12236822 2009-03-11
  • 打赏
  • 举报
回复
呵呵 谢谢大家了 解决了 郁闷。。

原来是写错了一个地方。。。。。


job='"+txt_job.text+"'
错写成job='"+txt_joy.text+"'

娘勒
lxf2000104 2009-03-11
  • 打赏
  • 举报
回复
是报错还是更新不成功,你把语句打印处理看看。
sql语法上没有错误啊。
只要不是int等类型,即使更新为''也不会有问题。
如果是更新不成功,会不会是主键txt_serch没有值。 where id='" + txt_serch.Text + "'
hongqi162 2009-03-11
  • 打赏
  • 举报
回复
public bool getupdata()
{
bool flag = false;
SqlConnection conn = null;
dbcon db = new dbcon();

string updatacmd = "update g_user set name='" + txt_name.Text + "',card='" + txt_card.Text + "',riqi='" + txt_money.Text + "',gtel='" + txt_gtel.Text + "',tel='" + txt_tel.Text + "',email='" + txt_email.Text + "',youbian='" + txt_youbian.Text + "',address='" + txt_add.Text + "',sex='" + txt_sex.Text + "',danbaoren='" + txt_danbaoren.Text + "', job='" + txt_joy.Text + "' where id='" + txt_serch.Text + "'";

try
{
conn = db.getcon();
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatacmd;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
return true;

}
catch { return false;}
finally{
conn.Close();
}
return flag;

}

protected void btn_tj_Click(object sender, EventArgs e)
{
if (getupdata())
{
Response.Write("<script>alert('修改成功!')</script>");
Response.Redirect("admin_.aspx");

}
else
lab_message.Text = "修改失败!!!";

}
CutBug 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 CutBug 的回复:]
估计又是这个问题
Page_Load里你给控件赋值的地方放在
if(!IsPostBack)
{
txt_name.Text =....
.....
}
[/Quote]
那应该是这个问题
QQ12236822 2009-03-11
  • 打赏
  • 举报
回复
没有报错
就是不能修改
修改不了 。。。
ilovew521527 2009-03-11
  • 打赏
  • 举报
回复
或者你可以把修改的代码放到数据库里面写上一些数据进行调试看看能不能修改成功,如果能 那么你就看下面的语句是那错了,如过不能你的SQL语句写错了
CZH_friend 2009-03-11
  • 打赏
  • 举报
回复
报什么错啊
liuyeede 2009-03-11
  • 打赏
  • 举报
回复
用参数去做吧,看到字符串中有单双引号就头晕,出错就难免了。
hellensee 2009-03-11
  • 打赏
  • 举报
回复
大家好
我是猎头公司的helen
现在有上海的。net开发的职位
4,5年的c#开发经验
英文可以沟通
项目很不错
难得的机会
有感兴趣的朋友联系我
msn:helensee@msn.cn
邮箱:helen@jingjie-wisemen.com
CutBug 2009-03-11
  • 打赏
  • 举报
回复
估计又是这个问题
Page_Load里你给控件赋值的地方放在
if(!IsPostBack)
{
txt_name.Text =....
.....
}
ilovew521527 2009-03-11
  • 打赏
  • 举报
回复
name='" + txt_name.Text + "',card='" + txt_card.Text + "' 你把语句的,号去掉试下看看
黑哥 2009-03-11
  • 打赏
  • 举报
回复
断点一下,调试一下

什么问题都看见了
金大哈 2009-03-11
  • 打赏
  • 举报
回复
试调一下 拷贝出最终的sql 出来 执行一下看看
金大哈 2009-03-11
  • 打赏
  • 举报
回复
trim 一下 先
HUOWEI 2009-03-11
  • 打赏
  • 举报
回复
数据库的字段类型可能和现在的所有输入类型不匹配的原因吧,你可以把输入的值,定义成变量,转化类型后再写入SQL语句.
QQ12236822 2009-03-11
  • 打赏
  • 举报
回复
类型没有错误
但是就是修改不了
2楼的是全部代码。。
QQ12236822 2009-03-11
  • 打赏
  • 举报
回复
    public bool getupdata()
{
bool flag = false;
SqlConnection conn = null;
dbcon db = new dbcon();

string updatacmd = "update g_user set name='" + txt_name.Text + "',card='" + txt_card.Text + "',riqi='" + txt_money.Text + "',gtel='" + txt_gtel.Text + "',tel='" + txt_tel.Text + "',email='" + txt_email.Text + "',youbian='" + txt_youbian.Text + "',address='" + txt_add.Text + "',sex='" + txt_sex.Text + "',danbaoren='" + txt_danbaoren.Text + "', job='" + txt_joy.Text + "' where id='" + txt_serch.Text + "'";

try
{
conn = db.getcon();
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatacmd;
cmd.Connection = conn;
SqlDataReader dr = cmd.ExecuteReader();
if (!dr.Read())
{
flag = true;

}
else flag = false;


}
catch { }
finally{
conn.Close();
}
return flag;

}

protected void btn_tj_Click(object sender, EventArgs e)
{
if (getupdata())
{
Response.Write("<script>alert('修改成功!')</script>");
Response.Redirect("admin_.aspx");

}
else
lab_message.Text = "修改失败!!!";

}
shuifengwyz1 2009-03-11
  • 打赏
  • 举报
回复
都是什么类型的啊

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧