0
訪問我的是,當我將數據插入到數據庫中的值都爲0數據似乎爲「0」時插入到用vb.net
我列StudentID,IntakeCode,名字的問題,姓氏,聯繫人號碼,電子郵件地址和unitID。
這是第一形式
If txtunitid.Text <> "" And txttp.Text <> "" Then
cmdInsert.CommandText = "INSERT INTO StudentAcc (StudentID, UnitID) VALUES ('" & txttp.Text & "', '" & txtunitid.Text & "');"
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
cmdInsert.ExecuteNonQuery()
cmdUpdate.CommandText = "UPDATE Accommodation SET Status = True WHERE Unit_ID = " & txtunitid.Text & ";"
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.Connection = cnnOLEDB
cmdUpdate.ExecuteNonQuery()
obj.Show()
MsgBox(txtunitid.Text & " " & "Record updated.")
Me.Hide()
Else
MsgBox("Hello")
End If
cmdUpdate.Dispose()
這是第二個形式
If intakecodetxt.Text <> "" And firstnametxt.Text <> "" And lastnametxt.Text <> "" And MaskedTextBox1.Text <> "" And emailtxt.Text <> "" And IsNumeric(firstnametxt.Text) = False And IsNumeric(lastnametxt.Text) = False Then
cmdUpdate.CommandText = "UPDATE Students SET IntakeCode = '" & intakecodetxt.Text & "', FirstName = '" & firstnametxt.Text & "', LastName = '" & lastnametxt.Text & "', ContactNumber = '" & MaskedTextBox1.Text & "', Email_Address = '" & emailtxt.Text & "' WHERE StudentID = '" & studentidtxt.Text & "';"
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.Connection = cnnOLEDB
cmdUpdate.ExecuteNonQuery()
MsgBox(studentidtxt.Text & " " & "Record updated.")
Else
MsgBox("Please Enter Value")
End If
cmdInsert.Dispose()
通過在將數據發送到數據庫之前立即將值記入日誌。這會告訴你它們是否實際上是非零值。 – Mathemats