救命,数据库更新错误 两百分求解

kld3000 2003-05-13 09:40:21
以下是主要代码
txtPassword1 原密码
txtPassword2 新密码
txtPassword3 确认密码

错误信息:
如果我用新密码是 XX,
那么它提示我

第 1 行: 'XX' 附近有语法错误。

还有一百分在:
http://expert.csdn.net/Expert/topic/1773/1773877.xml?temp=.8090937



Dim DBConn as OleDbConnection
Dim DBUpdate As New OleDbCommand
dim DBCommand as new oledbDataAdapter
dim DSpageData as new Dataset
DBConn = New OleDbConnection("Provider=sqloledb;" _
& "server=localhost;" _
& "Initial Catalog=os;" _
& "User Id=today;" _
& "Password=123123;")
dbcommand = new oledbDataAdapter _
("select userID,username,password from users where userName ='" &txtusername.text _
& "' and password = '"& txtPassword1.text _
& "'",dbconn)




DBCommand.Fill(DspageData, _
"userss")




If DSpageData.Tables("userss").Rows(0).item("password") = 0 Then
lblMessage.Text = "旧密码错误"

Else

DBUpdate.CommandText = "Update Users set " _
& " password=Convert(varchar(10),password) " _
& Replace (txtPassword2.Text,"'","''") _
& " where username= " _
& " &txtusername.text"

DBUpdate.Connection = DBConn
DBUpdate.Connection.Open
DBUpdate.ExecuteNonQuery()
'lblMessage.Text = lblMessage.Text & "用户名是: " & txtUserName.Text & "<BR>密码" & txtPassword2.Text
lblMessage.Text = "用户名是: " & txtUserName.Text & "<BR>密码" & txtPassword2.Text

end if



...全文
85 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kld3000 2003-05-27
  • 打赏
  • 举报
回复
我不会存储过程

而且工期紧,没机会学啊

我想作完这个一定要去好好学一下存储过程了
yqdeng 2003-05-13
  • 打赏
  • 举报
回复
SQL错了
  • 打赏
  • 举报
回复
你的SQL语句有错误,正确的应该是:
update Users set password=Convert(varchar(10),'wo de mima') where username='abce'
转换成程序就是我上面写的!
  • 打赏
  • 举报
回复
DBUpdate.CommandText = "Update Users set " _
& " password=Convert(varchar(10),'" _
& Replace (txtPassword2.Text,"'","''") _
& "') where username= '" _
& txtusername.text & "'"
wacle 2003-05-13
  • 打赏
  • 举报
回复
为什么不用存储过程?
用存储过程应该就不会有上面的问题了,因为存储过程不需要根据参数类型确定是否加'',减少出错率,建议试一试
killprograme 2003-05-13
  • 打赏
  • 举报
回复
你用oledbDataAdapter的selectcommand 添加参数,保证不会出错,不要用引号之类,很容易出错

62,074

社区成员

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

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

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

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