heroxianf
发表于 2016-10-27 12:14:30
本帖最后由 heroxianf 于 2016-10-27 13:14 编辑
回复 45# chzj589
好像是自定义函数的问题
kk_lee69
发表于 2016-10-27 13:05:08
回复 45# chzj589
會不會是文字 數字有沒有加 單引號問題??
chzj589
发表于 2016-10-27 13:25:03
本帖最后由 chzj589 于 2016-10-27 13:26 编辑
回复 47# kk_lee69
这是修改的代码:
原来是:SQLiteUpateName($TableName, GUICtrlRead($GUI_Input1), GUICtrlRead($GUI_Input2), GUICtrlRead($GUI_Input3))
我改为9个输入框
SQLiteUpateName($TableName, GUICtrlRead($GUI_Input1), GUICtrlRead($GUI_Input2), GUICtrlRead($GUI_Input3), GUICtrlRead($GUI_Input4), GUICtrlRead($GUI_Input5), GUICtrlRead($GUI_Input6), GUICtrlRead($GUI_Input7), GUICtrlRead($GUI_Input8), GUICtrlRead($GUI_Input9))
下面这个函数如何修改
Func SQLiteUpateName($TableName, $keyValue,$nameValue, $AgeValue)
运行提示:
"F:\SQLite 数据库\Excel导入MSSQL 数据库例子.au3"(401,68) : 错误: SQLiteUpateName() 函数调用行有 10 个参数. 函数定义需要参数最多 = 4. 此函数首次调用在行: 397.
就是说 函数定义需要参数最多 = 4
如何修改为函数定义需要参数最多 = 10
heroxianf
发表于 2016-10-27 13:26:49
回复 48# chzj589
Func SQLiteUpateName(你增加9个,这里对应也要增加到9个吧?)
kk_lee69
发表于 2016-10-27 13:36:06
回复 48# chzj589
能貼上
Func SQLiteUpateName($TableName, $keyValue,$nameValue, $AgeValue)
這個 Func 的全部內容嗎??
chzj589
发表于 2016-10-27 13:39:14
本帖最后由 chzj589 于 2016-10-27 13:43 编辑
回复 49# heroxianf
您帮忙看一看,要怎样修改
Func _ButtonReset()
;Case $Msg = $GUI_ButtonReset;更改
If ThisStringIsEmpty($GUI_Input2) Then
MsgBox(0, "错误提示..", "目前只能通过编号更改,请输入编号!")
ThisInputClear()
Else
SQLiteUpateName($TableName, GUICtrlRead($GUI_Input1), GUICtrlRead($GUI_Input2), GUICtrlRead($GUI_Input3), GUICtrlRead($GUI_Input4), GUICtrlRead($GUI_Input5), GUICtrlRead($GUI_Input6), GUICtrlRead($GUI_Input7), GUICtrlRead($GUI_Input8), GUICtrlRead($GUI_Input9))
EndIf
EndFunc ;==>_ButtonReset
;keyValue是匹配健namevalue是新名字
Func SQLiteUpateName($TableName, $a, $b, $c, $d, $e, $f, $keyValue, $nameValue, $AgeValue)
;$keyValue1, $keyValue2, $keyValue3, $keyValue4,
GUICtrlSendMsg($GUI_ListBox, $LVM_DELETEALLITEMS, 0, 0)
ConsoleWrite($keyValue & @LF)
ConsoleWrite($nameValue & @LF)
ConsoleWrite($AgeValue & @LF)
_SQLite_Open($SQLite_Data_Path)
_SQLite_QuerySingleRow(-1, "SELECT IDs FROM people WHERE IDs = '" & $keyValue & "' ;", $aRow)
Local $empty = $aRow
If $empty = "" Then
MsgBox(0, "错误提示", "您输入的编号不存在,请重新输入")
EndIf
_SQLite_Exec(-1, "UPDATE people SET NAME = '" & $nameValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age1 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age2 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age3 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age4 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age5 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age6 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Exec(-1, "UPDATE people SET Age7 = '" & $AgeValue & "' WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Close()
EndFunc ;==>SQLiteUpateName
$a, $b, $c, $d, $e,是我加上去的,不行
heroxianf
发表于 2016-10-27 13:48:59
回复 51# chzj589
这是上边的示例,在用UPDATE更新数据,也要写全表的样子,你参照着改一下呢。
#region ;更新数据
$sEXEC = "UPDATE 物品清单 SET 肉类 = '羊肉', 水果 = '香蕉', 家具 = '柜子', 备注 = '17-5-8-15' WHERE 蔬菜 = '生菜';"
_SQLite_Exec($hdb, $sEXEC)
heroxianf
发表于 2016-10-27 13:54:19
回复 51# chzj589
还有一个注意点就是,你在增加9个新增内容后,初期建立的数据库表也应该是9个,这样才能成功添加数据
chzj589
发表于 2016-10-27 13:59:45
回复 53# heroxianf
有建立,添加,查询,读取都是9个能通过,就是修改被函数卡住了
kk_lee69
发表于 2016-10-27 13:59:57
回复 51# chzj589
你的目的是 輸入 人員 編號 更改 基本資料嗎??
chzj589
发表于 2016-10-27 14:01:41
回复 55# kk_lee69
修改一条数据库的资料
kk_lee69
发表于 2016-10-27 14:08:50
回复 56# chzj589
Func SQLiteUpateName($TableName,$keyValue, $nameValue, $AgeValue1,$AgeValue2,$AgeValue3,$AgeValue4,$AgeValue5,$AgeValue6,$AgeValue7,$AgeValue8)
;$keyValue1, $keyValue2, $keyValue3, $keyValue4,
GUICtrlSendMsg($GUI_ListBox, $LVM_DELETEALLITEMS, 0, 0)
ConsoleWrite($keyValue & @LF)
ConsoleWrite($nameValue & @LF)
ConsoleWrite($AgeValue & @LF)
_SQLite_Open($SQLite_Data_Path)
_SQLite_QuerySingleRow(-1, "SELECT IDs FROM people WHERE IDs = '" & $keyValue & "' ;", $aRow)
Local $empty = $aRow
If $empty = "" Then
MsgBox(0, "??提示", "您?入的??不存在,?重新?入")
EndIf
_SQLite_Exec(-1, "UPDATE people SET NAME = '" & $nameValue & "' , Age='"&$AgeValue1&"',Age1='"&$AgeValue2&"',Age2='"&$AgeValue3&"',Age3='"&$AgeValue4&"',Age4='"&$AgeValue5&"',Age5='"&$AgeValue6&"',Age6='"&$AgeValue7&"',Age7='"&$AgeValue8&"'WHERE IDs = '" & $keyValue & "' ;")
_SQLite_Close()
EndFunc ;==>SQLiteUpateName
$keyValue人員編號
$nameValue姓名
kk_lee69
发表于 2016-10-27 14:12:50
回复 56# chzj589
UPDATE 兩三個位置的值不用寫成 三次
一個語句 就可以
UPDATEPEOPLESET 姓名='張三' ,年紀=21, 學歷='大學'Where人員編號='A001'
不用寫成
UPDATEPEOPLESET 姓名='張三'Where人員編號='A001'
UPDATEPEOPLESET 年紀=21Where人員編號='A001'
UPDATEPEOPLESET 學歷='大學'Where人員編號='A001'
heroxianf
发表于 2016-10-27 14:24:31
回复 56# chzj589
确实 测试可行,你再仔细看看呢。整完了,贴源码嘛~
#region ;更新数据
$sEXEC = "UPDATE 物品清单 SET 肉类 = 'test', 水果 = '香蕉', 家具 = '柜子', 备注 = '17-5-8-15' WHERE 蔬菜 = '生菜';"
_SQLite_Exec($hdb, $sEXEC)
chzj589
发表于 2016-10-27 15:19:57
回复 58# kk_lee69
谢谢!通过了。
还有添加可改为一条语句?
Func SQLiteInsert($a, $b, $c, $d, $e, $f, $g, $h, $i)
_SQLite_Open($SQLite_Data_Path)
;Read out the first row of the result from the specified query.
_SQLite_QuerySingleRow(-1, "SELECT IDs FROM " & $TableName & " WHERE IDs = '" & $a & "';", $aRow)
$Temp = $aRow
If $Temp = "" Then
_SQLite_Exec(-1, "Insert into " & $TableName & " (IDs) values ('" & $a & "');")
EndIf
MsgBox(4096, "提示:", $a)
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Name = '" & $b & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age = '" & $c & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age1 = '" & $d & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age2 = '" & $e & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age3 = '" & $f & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age4 = '" & $g & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age5 = '" & $h & "' WHERE IDs = '" & $a & "';")
_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age6 = '" & $i & "' WHERE IDs = '" & $a & "';")
;_SQLite_Exec(-1, "UPDATE " & $TableName & " SET Age7 = '" & $i & "' WHERE IDs = '" & $a & "';")
_SQLite_Close()
EndFunc ;==>SQLiteInsert