请教一个问题

bluefeilin 2006-10-27 05:52:48
这是我更新数据库中数据的一些代码,调式的时候没有出现任何的错误,但是就是更新不了数据库中表中的数据,请问这是怎么一会事啊。
string uno=Session["usno"].ToString().Trim();
string strConnection=System.Configuration.ConfigurationSettings.AppSettings["connectionstring"].ToString();
SqlConnection conn=new SqlConnection(strConnection);
string strdate = TB_shijian.Text;
DateTime dt = Convert.ToDateTime(strdate);
string selectstr="update shenqing set sname='"+TB_sname.Text+"',xibie='"+TB_xi.Text+"',zhuanye='"+TB_zhuanye.Text+"',ji='"
+TB_ji.Text+"',shijian='"+dt+"',sqjine='"
+TB_jine.Text+"' where sno='"+uno+"'";
SqlCommand addcommand=new SqlCommand(selectstr,conn);
conn.Open();
addcommand.ExecuteNonQuery();
conn.Close();
...全文
54 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujia_0421 2006-10-28
  • 打赏
  • 举报
回复
这段代码写得有问题:
string selectstr="update shenqing set sname='"+TB_sname.Text+"',xibie='"+TB_xi.Text+"',zhuanye='"+TB_zhuanye.Text+"',ji='"
+TB_ji.Text+"',ban='"+TB_class.Text+"',xuezhi='"+TB_xuezhi.Text+"',liyou='"+TB_liyou.Text+"',qixian='"
+TB_qixian.Text+"',shenqingren='"+TB_shenqing.Text+"',shijian='"+dt+"',sqjine='"
+TB_jine.Text+"' where sno='"+uno+"'";


因为TB_qixian.Text....已经是string类型的,所以不需要再加单引号,即改为如下:
string selectstr="update shenqing set sname="+TB_sname.Text+",xibie="+TB_xi.Text+..
后面的楼主自己改吧.
具体我也没有测试,楼主不妨试一下看.....
liujia_0421 2006-10-27
  • 打赏
  • 举报
回复
我曾经也遇到过这样的问题,也是这么找的....
liujia_0421 2006-10-27
  • 打赏
  • 举报
回复
楼主断点调试一下,看"selectstr"在执行到断点时,到底是一个什么样的字符串,然后贴出来,大家再帮你查看一下原因...
happyf101 2006-10-27
  • 打赏
  • 举报
回复
string uno=Session["usno"].ToString().Trim();
string strdate = TB_shijian.Text;
string strConnection=System.Configuration.ConfigurationSettings.AppSettings["connectionstring"].ToString();
using(SqlConnection conn=new SqlConnection(strConnection))
{
conn.Open();
DateTime dt = Convert.ToDateTime(strdate);
string selectstr = string.Format("update shenqing set sname={0},xibie={1},zhuanye ={2},ji ={3},shijian = {4} where sno ={5}",TB_sname.Text,..,...,...,..,);
SqlCommand addcommand=new SqlCommand(selectstr,conn);
addcommand.ExecuteNonQuery();
conn.Close();
}
lizhizhe2000 2006-10-27
  • 打赏
  • 举报
回复
我估计是 where sno='"+uno+"'";
不应该用单引号,如果是数字型的
因为条件不足
楼主可单步下把selectst放到SQL查询分析器中执行下
bluefeilin 2006-10-27
  • 打赏
  • 举报
回复
还是不行啊,表中的内容没有作任何的改变。
icehawk 2006-10-27
  • 打赏
  • 举报
回复
string uno=Session["usno"].ToString().Trim();
string strConnection=System.Configuration.ConfigurationSettings.AppSettings["connectionstring"].ToString();
SqlConnection conn=new SqlConnection(strConnection);
string strdate = TB_shijian.Text;
DateTime dt = Convert.ToDateTime(strdate);
string selectstr="update shenqing set sname='"+TB_sname.Text+"',xibie='"+TB_xi.Text+"',zhuanye='"+TB_zhuanye.Text+"',ji='"
+TB_ji.Text+"',shijian=@shijian,sqjine='"
+TB_jine.Text+"' where sno='"+uno+"'";
SqlCommand addcommand=new SqlCommand(selectstr,conn);
SqlParameter parameter = addcommand.Parameters.Add(
"@shijian", SqlDbType.DateTime);
parameter.Value = dt;
conn.Open();
addcommand.ExecuteNonQuery();
conn.Close();

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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