Hi
I am a new bee, I am trying to insert data into a database white the use of parameters. When I run this code I get an error message: "No value given for one or more required parameters."
Any help will be appreciated

    conn.Open()

    sql = "INSERT INTO Categories(Name)  VALUES ( @PName)"
    cm.Parameters.Clear()

    cm.Parameters.Add("@PName", OleDb.OleDbType.LongVarChar).Value = Pname



    cm = New OleDb.OleDbCommand(sql, conn)
    cm.ExecuteNonQuery()
    conn.Close()

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Please make sure you get your code tags right when posting:

[code=vb.net] ...code here....

[/code]

Next please paste the complete method you're using to upload. It looks like your PName variable in VB.NET is likely null (Nothing).

Hi
here is the code
I am giving a value to Pname stil nothing.

Dim Pname As String = "1'23"
        Dim PDesc As String = "123"
        Dim pseq As String = "1"



        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\db\help\123.mdb"
        conn.Open()
       
        sql = "INSERT INTO Categories(Name)  VALUES ( @PName)"
        cm.Parameters.Clear()
   
        cm.Parameters.Add("@PName", OleDb.OleDbType.VarChar)
        cm.Parameters(0).Value = Pname
        cm = New OleDb.OleDbCommand(sql, conn)
        cm.ExecuteNonQuery()
        conn.Close()

Hi!

You must have qoutationmarks around the value you want to insert. Try this: sql = "INSERT INTO Categories(Name) VALUES ('" & @PName & "')"

Dim Pname As String = "1'23"

Dim PDesc As String = "123"

Dim pseq As String = "1"

 

 

 

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\db\help\123.mdb"

conn.Open()

 

sql = "INSERT INTO Categories(Name) VALUES ( @PName)"

cm = New OleDb.OleDbCommand(sql, conn)
cm.Parameters.Clear()

 

cm.Parameters.Add("@PName", OleDb.OleDbType.VarChar)

cm.Parameters(0).Value = Pname



cm.ExecuteNonQuery()

conn.Close()

Thanks for helping the code works like this.

This question has already been answered. Start a new discussion instead.