Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42406

VS 2010 Insert a row into MSACCESS 2010 database

$
0
0
Hello everyone.

I googled a lot about this but results didn't help.

However, I was able to read records from the database witht the following codes that google gave me.

Code:

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Dim rows As OleDbDataReader

        con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\res\database.accdb; Persist Security Info=false;")
        con.Open()
        cmd = New OleDbCommand("SELECT * FROM EmployeeDetails", con)
        rows = cmd.ExecuteReader()

I was trying to do the following way.
Code:

Try
            Dim con As OleDbConnection
            Dim cmd As OleDbCommand

            con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\res\database.accdb; Persist Security Info=false;")
            con.Open()

            cmd = New OleDbCommand("INSERT INTO EmployeeDetails (empName, Gender, DOB, Address, ContactNo, Salary, JobTitle, DateJoined, Picture)" & _
                                "VALUES ('" & empName & "','" & empGender & "',#" & empDOB & "#,'" & empAddress & "'," & empContactNo & "," & empSalary & ",'" & empJobTitle & "',#" & empJoinDate & "#,'" & empPicture & "')", con)
            cmd.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

And it returned "DATA TYPE MISMATCH in expression criteria".

I'm a PHP MySQL programmer. So, I'm not really sure if my query string is correct.

Viewing all articles
Browse latest Browse all 42406

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>