Click here to Skip to main content
15,884,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Sorry but im having problems with the account (kentoncongs) i dont know why i cant login to my account here I tried to select "forget password?" but i didnt even receive the mail, in inbox or in my spam... well nevertheless tnx for the replies.

(addressed to OriginalGriff), i tried that parameter thing but still same error in the executenonquery

here is the screenshot of the error..


<img src="http://i.imgur.com/VGdiHAP.jpg" title="source: imgur.com" />


full code here:


VB
Public Class con_info
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String

    Private Sub Bene_recordsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bene_recordsBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Bene_recordsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Bene_dbDataSet)

    End Sub

    Private Sub con_info_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Bene_dbDataSet.bene_records' table. You can move, or remove it, as needed.
        Me.Bene_recordsTableAdapter.Fill(Me.Bene_dbDataSet.bene_records)

        con = New OleDb.OleDbConnection
        dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Users\RedemptorisMater\Desktop\S..\Kenton\B...\bene_db.mdb"

        con.ConnectionString = dbProvider & dbSource

        btnSave.Enabled = True
        btnClose.Enabled = True

        F_nameTextBox.Clear()
        M_nameTextBox.Clear()
        L_nameTextBox.Clear()

        AddTextBox.Clear()
        Home_numTextBox.Clear()
        Cell_numTextBox.Clear()

    End Sub
    Private Sub RefreshData()

        If Not con.State = ConnectionState.Open Then
            con.Open()
        End If

        Dim da As OleDb.OleDbDataAdapter
        Dim Sql As String

        Sql = "SELECT * FROM bene_records"
        da = New OleDb.OleDbDataAdapter(Sql, con)

        Dim dt As New DataTable
        da.Fill(dt)

        con.Close()

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim cmd As New OleDb.OleDbCommand
        Dim inc As Integer
        Dim ds As New DataSet


        If Not con.State = ConnectionState.Open Then
            con.Open()

        End If
        cmd.Connection = con
        cmd.CommandText = "INSERT INTO bene_records(f_name, m_name, l_name, b_date, add, home_num, cell_num)VALUES(@F_nameTextBox, @M_nameTextBox, @L_nameTextBox, @B_dateDateTimePicker, @AddTextBox, @Home_numTextBox, @Cell_numTextBox)"
        cmd.Parameters.AddWithValue("@F_nameTextBox", F_nameTextBox.Text)
        cmd.Parameters.AddWithValue("@M_nameTextBox", M_nameTextBox.Text)
        cmd.Parameters.AddWithValue("@L_nameTextBox", L_nameTextBox.Text)
        cmd.Parameters.AddWithValue("@B_dateDateTimePicker", B_dateDateTimePicker)
        cmd.Parameters.AddWithValue("@AddTextBox", AddTextBox.Text)
        cmd.Parameters.AddWithValue("@Home_numTextBox", Home_numTextBox.Text)
        cmd.Parameters.AddWithValue("@Cell_numTextBox", Cell_numTextBox.Text)
        cmd.ExecuteNonQuery()

        RefreshData()

        con.Close()

    End Sub
End Class
Posted

a quick look and it 'seems' ok, with this exception

cmd.Parameters.AddWithValue("@B_dateDateTimePicker", B_dateDateTimePicker)


I don't know what data type the b_date column in the database is, but Im also tempted to suggest that you should be doing something like

cmd.Parameters.AddWithValue("@B_dateDateTimePicker", B_dateDateTimePicker.Value)


depending on the data type for the b_date column, you'd need the result (.Value) to be in the correct format for the database - Im thinking you might also need to do a .ToString() on that value

my suggestion would be, if its possible, to print out/dump the exact SQL that's been formed, right before the
cmd.ExecuteNonQuery(); 
statement and see if it looks ok

if none of this works you'll have to wait and see if OG is awake or anyone else has any ideas
 
Share this answer
 
v2
Comments
Member 11194404 30-Oct-14 22:23pm    
the b_date in the db has the data type of Date/Time

i tried

cmd.Parameters.AddWithValue("@B_dateDateTimePicker", B_dateDateTimePicker.Value)

but still the same error.
hmm can you enlighten me up a little bit with the .ToString() kinda rusty on this codes again.. im just new in the visual studio thing. Tnx.
Garth J Lancaster 30-Oct-14 23:56pm    
looks like you've solved the issues with help from DamithSL - the answer to the question asked me was

B_dateTimePicker.Value.ToString("YYYY-MM-DD HH:NN:SS");

where "YYYY-MM-DD HH:NN:SS" appears to be suitable as a date format for MSAccess
Member 11194404 31-Oct-14 2:27am    
well i didnt really use the ToString, my error was just the location of my db.. i forgot to check were was it stored.. well i got another problem... can you help me with this one

http://www.codeproject.com/Questions/835167/How-to-make-the-DataGridView-output-only-the-data?arn=0
you need to use [] for the reserved sql keywords as column names

SQL
INSERT INTO bene_records(f_name, m_name, l_name, b_date, [add], home_num, cell_num)VALUES(@F_nameTextBox, @M_nameTextBox, @L_nameTextBox, @B_dateDateTimePicker, @AddTextBox, @Home_numTextBox, @Cell_numTextBox)


check List of Microsoft Jet 4.0 reserved words[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900