• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

No value given for one or more required parameters.

I get No value given for one or more required parameters. for

Public Class trackuser

    Public Shared Sub trackusers(ByVal thepage As String)
        Using con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\perkinj\My Documents\Visual Studio 2010\WebSites\runningprofiles\forums\forum.mdb")
            Using cmd As New OleDbCommand("INSERT into nousersonline (`Username`,`Activity`,`PageUrl`,`ActivityDate`) VALUES (test1,test2," & thepage & ",test4)", con)
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End Using
        End Using
    End Sub

End Class

Open in new window

0
runnerjp2005
Asked:
runnerjp2005
2 Solutions
 
Asim NazirCommented:
See if there is any primary key in the table and may be if that is not auto-generated then you need to pass that as well. Rest looks fine to me.
0
 
runnerjp2005Author Commented:
I have ActivityLogID and that is my primary and i have set this to autonumber (access)
0
 
TonyRebaCommented:
Using cmd As New OleDbCommand("INSERT into nousersonline (`Username`,`Activity`,`PageUrl`,`ActivityDate`) VALUES (test1,test2," & thepage & ",test4)", con)


Make sure you are pulling the values inserted , this usually means that values are not being pulled ,,,
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Asim NazirCommented:
Ok. Then follow below links:

Here is helpful comment from the same links:
When using OLEDB with ADO.NET named parameters are unsupported. Instead, remove the parameter names from your SQL statement and replace each with a question mark. In addition, you can remove the parameter names when adding parameters to the Parameter collection. Just make certain to add them to the collection in the order which corresponds to their order in the SQL statement.

http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/6e06fe86-b946-4803-973f-8604d335c776/
0
 
CodeCruiserCommented:
Try changing this line

Using cmd As New OleDbCommand("INSERT into nousersonline (`Username`,`Activity`,`PageUrl`,`ActivityDate`) VALUES (test1,test2," & thepage & ",test4)", con)


to


Using cmd As New OleDbCommand("INSERT into nousersonline (Username,Activity,PageUrl,ActivityDate) VALUES (test1,test2, '" & thepage & "',test4)", con)


Note that I have added single quotes(') around the value of thepage because I assumed it would be a varchar. If other columns are varchars then you need to enclose those values in quotes as well. For example, if the UserName is varchar then


Using cmd As New OleDbCommand("INSERT into nousersonline (Username,Activity,PageUrl,ActivityDate) VALUES ('test1',test2, '" & thepage & "',test4)", con)
0
 
TonyRebaCommented:
That might be also the problem ,

in that case use something like
InsertCommand="INSERT INTO [nousersonline](Username....) VALUES (?,?,?,?) "  >
0
 
Jeff CertainCommented:
As CodeCruiser said (and I pointed out in your other related question), the issue is that it doesn't know what test1, etc are. It tries to assume they're parameters with no values. However, you can get around this by making it see them as string literals, by putting single quotes around the values you're trying to insert.

Generally when this sort of issue pops up, you can always try running it directly agaisnt SQL Server to see if it's a problem with your code or your query.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now