Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > error on OleDbException
 

error on OleDbException

OleDbException was unhandled by code

Error details: the changed u requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

Vbform code

Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Are you sure want to log out?", "BEST PIZZA Ver. 1.0", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Dim sqlUser As String

With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With

sqlUser = "Insert into loghistory values('" & strUserName & "','" & strUserTextStatus & "','" & Format(Now, "dd-MMM-yy") & "','" & Format(Now, "Long Time") & "','" & strUserName & "(Logout)" & "')"
Dim datacommand As New OleDb.OleDbCommand(sqlUser, Conn)
datacommand.ExecuteNonQuery()

Dim strSQL As String
strSQL = "UPDATE login SET IsLogin = 'Logout' WHERE username = '" & strUserName & "'"
Dim cmdUpdateLogin As New OleDbCommand(strSQL, Conn)
cmdUpdateLogin.ExecuteNonQuery()
Conn.Close()
Me.Close()
Else
e.Cancel = True
End If
End Sub


loghistory table

pk userid text
pk type text
pk date date/time
pk time date/time

please help me
description text

ang3la  Thursday, May 01, 2008 4:17 AM

The structure of the database is wierd usually you can only have one primary key for a database. I would not make the userid or type a primary key because there will be duplicates in the table. I would use an autonumber, guid, or timestamp as the primarykey

Ken Tucker  Thursday, May 01, 2008 10:38 AM

The structure of the database is wierd usually you can only have one primary key for a database. I would not make the userid or type a primary key because there will be duplicates in the table. I would use an autonumber, guid, or timestamp as the primarykey

Ken Tucker  Thursday, May 01, 2008 10:38 AM
so what should i do??

ang3la  Thursday, May 01, 2008 5:14 PM

You can use google to search for other answers

Custom Search

More Threads

• Retrieving the combobox.SelectedValue
• time tracker
• how to set image property of picturebox to what it is displaying
• Why I can not set any DefaultCellStyle after I set DataSource
• Problem inserting a new record with VB 2005 using a table adaptor and SQL 2005 Express
• System.IndexOutofRangeException ... Index {{X}} does not have a value...
• Form validation -validate everything at once
• DataGridView Sorting
• "datagridviewcomboxcell value is not valid" when i want to bind object to datagridviewcell
• The Old Datagrid Button Question...