2015-09-17 43 views
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() 
+0

通過在將數據發送到數據庫之前立即將值記入日誌。這會告訴你它們是否實際上是非零值。 – Mathemats

回答

0

在第一條語句,你似乎試圖用引號括的StudentId和單元ID字段,表示他們是字符值而在第二個語句中,您似乎將UnitId引用爲數字值。我懷疑它是一個數字字段,而你傳遞的字符串正在被轉換爲零。