Dear All
I wrote a code to save a data using text box but there are some error like : ArguimentException was unhandled. Cannot bind to the property or column User Privilege on the DataSource.Parameter name: dataMember

My code for saving is :

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Dim Con As OleDb.OleDbConnection
        Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Pfectrol\My Documents\Visual Studio 2008\db\CoolMate.mdb;"
        Try
            Dim strSQL As String = "INSERT INTO Equipment (Port_Number,Display_Name, Equipment, Tonnage,User_Privilage) VALUES (@Port_Number, Display_Name, @Equipment, @Tonnage, @User_Privilage);"
            Dim cmd As New OleDb.OleDbCommand(strSQL)
            Con = New OleDb.OleDbConnection(strConnection)
            cmd.Connection = Con
            Con.Open()
            cmd.ExecuteNonQuery()
            Con.Close()

        Catch ex As Exception
            Trace.WriteLine(ex.ToString)
        End Try
        cmd.Dispose()
        cmd = Nothing
        
    End Sub

and used module for connection and its code is like

Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

Imports System.ArgumentException

Module ModCool

   
    Public Function Chiller() As OleDb.OleDbConnection

        Dim Con As OleDb.OleDbConnection

        Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Pfectrol\My Documents\Visual Studio 2008\db\CoolMate.mdb;")

        Return Con

        Con = Nothing

    End Function



    Public bool As Boolean

    Public da As OleDb.OleDbDataAdapter

    Public dtable As New DataTable

    Public i As Int16

    Public cmd As OleDb.OleDbCommand

    Public da1 As OleDb.OleDbDataAdapter

    Public strSQL As String

    Public CB As OleDb.OleDbCommandBuilder

    Public con = ModCool.Chiller



End Module

Any one can Help me Please its really hurry

Some time ago I discovered that with both Microsoft Access and SQL Server the operating system, i.e., Windows, doesn't like databases anywhere at all in \Documents And Settings\...

It might work if you put the .mdb file somewhere else.

I got my fault. I changed my column name in db and doesn't bind text box after that. I change it and I got better result

After compiling there is no error, When I add some values in text box and click on Save button an error message with heading OleDbException was unhandled and it says: No value given for one or more required parameters.. this msgbox point to cmd.ExecuteNonQuery()

Parameters?

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Dim Con As OleDb.OleDbConnection
        Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Pfectrol\My Documents\Visual Studio 2008\db\CoolMate.mdb;"
        Try
            Dim strSQL As String = "INSERT INTO Equipment (Port_Number,Display_Name, Equipment, Tonnage,User_Privilage) VALUES (@Port_Number, @Display_Name, @Equipment, @Tonnage, @User_Privilage)"
            Dim cmd As New OleDb.OleDbCommand(strSQL)
            Con = New OleDb.OleDbConnection(strConnection)
            cmd.Connection = Con

            cmd.Parameters.AddWithValue("@Port_Number",10)
            cmd.Parameters.AddWithValue("@Display","Value...")
            cmd.Parameters.AddWithValue("@Equipment","Value...")
            cmd.Parameters.AddWithValue("@Tonnage","Value...")
            cmd.Parameters.AddWithValue("@User_Privilage","Value...")

            Con.Open()
            cmd.ExecuteNonQuery()
            Con.Close()

        Catch ex As Exception
            Trace.WriteLine(ex.ToString)
        End Try
        cmd.Dispose()
        cmd = Nothing
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.