主题:  一个字:怪

mrhgw

职务:普通成员
等级:1
金币:0.0
发贴:29
#12002/12/23 16:15:29
1. 用DataGrid中显示记录,然后用EDIT--UPDATE进行更新;
2. debug也没有检查出错误,总之一切正常;
3. 就是EDIT时不能更新数据,其间try…catch 语名中的还显示:更新成功,可看看数据库中还是一样的没有更新,真的不知道怎么回事。
请版主帮我看看有什么问题……
请看原码:(VB)

sub dataGrid1_update(obj as object,e as DataGridCommandEventargs)
    dim cols() as string = {"Name","Fwage","WorkDay","WorkHour" , _
     "AddDay","AddHour","RestDay","RestHour","foreMoney","EatsMoney" , _
     "PowerMoney","charterMoney","others"}
    dim I as integer
    dim strstate as string
dim params(12) as string
dim Updatecmd as string
    for I = 0 to 12
     dim currentTextbox as textBox
     currentTextbox = e.item.findControl("edit_" & cols(I))
     dim colvalue as string = currentTextbox.text
     params(I) = colvalue
next
    
UpdateCmd = "update wage set Name=@Name,Fwage=@Fwage, " _
     & " WorkDay=@WorkDay,WorkHour=@WorkHour,AddDay=@AddDay,AddHour=@AddHour, " _
     & " RestDay=@RestDay,RestHour=@RestHour,foreMoney=@foreMoney,EatsMoney=@EatsMoney, " _
         & " PowerMoney=@PowerMoney,charterMoney=@charterMoney,others=@others where ID=@id "
        
dim Dbcommand as oledbCommand
Dbcommand = new oledbCommand(UpdateCmd , Dbconn)
Dim objParam as oledbParameter

objParam = new oledbParameter("@Name",oledbType.char)
objParam.value = params(0)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@Fwage",oledbType.double)
objParam.value = params(1)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@WorkDay",oledbType.double)
objParam.value = params(2)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@WorkHour",oledbType.double)
objParam.value = params(3)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@AddDay",oledbType.double)
objParam.value = params(4)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@AddHour",oledbType.double)
objParam.value = params(5)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@RestDay",oledbType.double)
objParam.value = params(6)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@RestHour",oledbType.double)
objParam.value = params(7)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@foreMoney",oledbType.double)
objParam.value = params(8)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@EatsMoney",oledbType.double)
objParam.value = params(9)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@PowerMoney",oledbType.double)
objParam.value = params(10)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@charterMoney",oledbType.double)
objParam.value = params(11)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@others",oledbType.double)
objParam.value = params(12)
Dbcommand.parameters.add(objParam)

objParam = new oledbParameter("@id",oledbType.integer)
objParam.value = DataGrid1.DataKeys(cint(e.item.itemIndex))
Dbcommand.parameters.add(objParam)

Dbcommand.connection.open
Try
DbCommand.ExecuteNonQuery()
lblMessage.InnerHtml = "¹§Ï²£¬ÄãÒѳɹ¦¸üÐÂÁËÊý¾Ý£¡
"
DataGrid1.EditItemIndex = -1
Catch Ex As oledbException
lblMessage.InnerHtml="Error message!"
end try
Dbcommand.connection.close
BindGrid()
end sub



mrhgw

职务:普通成员
等级:1
金币:0.0
发贴:29
#22002/12/23 16:29:58
再说一句:
我用同样的方法也做过另一个页面,可以正常的更新。
我的这个页面就是修改那个做了,可就是……真是怪也



5D荣誉版主

职务:普通成员
等级:1
金币:10.0
发贴:271
#32002/12/24 8:31:47
我一直用C#呵,不过还是仔细看了看你的代码,是有点怪,既然已经执行了try后面的语句,那应该前面的数据库的更新没有问题.我想如果有问题的话是不是数据库更新语句的参数要跟你设定的参数类型匹配?