Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Imports System.Data.OleDb

Public Class SongEntry
    Dim Provider As String
    Dim dataFile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
    End Sub

    Private Sub SongEntry_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        Provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
        dataFile = "C:\Users\User\Desktop\Song.accdb"
        connString = Provider & dataFile
        myConnection.ConnectionString = connString
        myConnection.Open()
        Dim str As String
        str = "Insert into MAS_SONGS([SM_CODE],[SM_EDESC],[SM_TDESC],[SM_SONGL1],[SM_SONGL2]) values (?,?,?,?,?)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)

        cmd.Parameters.AddWithValue("SM_CODE", TextBox3.Text)
        cmd.Parameters.AddWithValue("SM_EDESC", TextBox1.Text)
        cmd.Parameters.AddWithValue("SM_TDESC", TextBox2.Text)
        cmd.Parameters.AddWithValue("SM_SONGL1", TextBox4.Text)
        cmd.Parameters.AddWithValue("SM_SONGL2", TextBox5.Text)
       

        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            myConnection.Close()
            Me.Hide()

            TextBox1.Clear()
            TextBox2.Clear()
            TextBox3.Clear()
            TextBox4.Clear()
            TextBox5.Clear()

        Catch ex As Exception
            MsgBox(ex.Message)


        End Try


    End Sub
End Class


What I have tried:

Hi, i have made data Insert from Vb.Net to Ms access database but when click save button it says  "Data Mismatch in criteria expression" Note : SM_CODE is my primary key
Posted
Updated 13-Oct-19 4:31am

We can't tell - it's too dependent on the contents of your textboxes, which we have no access to.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
We also don't know what your table schema is like. It would also be that one or more of your table columns in numeric and you're trying to put a string into it.

The AddWithValue method will NOT convert text in a textbox into a numeric type for you.

I never use AddWithValuie because it sets up the parameter with a database type that it GUESSES AT based on the value that you pass into it.
 
Share this answer
 

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