0
他那裏所有, 我正在工作一個CMS,而嘗試更新命令更新記錄,它不工作。檢查更新命令,我的語法錯了嗎?
這裏是爲更新米完整的代碼,
Dim ID, RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone, CheckupDate, Disease, BloodGroup, Doctor, Remarks As String
RegNo = txtRegNo.Text
BedNo = CmbBedNo.SelectedItem.ToString()
BedType = CmbBedType.SelectedItem.ToString()
Charges = txtCharges.Text
PatName = txtPatName.Text
PatAge = txtPatAge.Text
PatAddr = txtPatAdd.Text
Phone = txtPhone.Text
CheckupDate = txtDate.Text
Disease = txtDisease.Text
BloodGroup = cmbBloodGrp.SelectedItem.ToString()
Doctor = cmbDoctor.SelectedItem.ToString()
Remarks = txtRemarks.Text
ID = txtRegNo.Text
Dim conStudent As New OleDbConnection
Dim comStudent As New OleDbCommand
conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DBProject\hspms.mdb"
conStudent.Open()
comStudent.CommandText = "UPDATE AdmitPt SET ID =" & ID & ", Bedcategory='" & BedType & "', BedNo=" & BedNo & ", BedCharges=" & Charges & ", PtName='" & PatName & "', PtAge=" & PatAge & ", Address='" & PatAddr & "', PhoneNo='" & Phone & "', Dates='" & CheckupDate & "', Disease='" & Disease & "', BloodGroup='" & BloodGroup & "', Doctor='" & Doctor & "', Remarks='" & Remarks & "' WHERE ID=" & RegNo
comStudent.Connection = conStudent
comStudent.CommandType = CommandType.Text
If (comStudent.ExecuteNonQuery() > 0) Then
MsgBox("record successfully updated")
End If
conStudent.Close()
一件事,就是用ID,BedNo,BedCharges,年齡命名字段設置爲數字數據類型。
如果有什麼不工作,你真的需要給錯誤信息,或某種指示爲*如果你想得到有用的答案,*什麼*不工作。此外,您應該真正使用查詢參數,而不是字符串連接,因爲此刻您很容易受到SQL注入的影響(更不用說每當有人在他們的名字中使用撇號時就會遇到錯誤) – Iridium
沒有錯誤消息,但是在運行查詢後數據庫不會更新。 – Qaiser
然後,不執行更新數據庫的代碼,或者WHERE子句中的部分不能按預期方式工作,並且類型塊更新 – nimdil