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()

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.

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.