No accessible 'item' can be called with these arguments

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 2359 Views - Last Post: 17 August 2010 - 11:16 AM Rate Topic: -----

#1 Guest_Guest*


Reputation:

No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 07:45 AM

Here's my sql string in which I'm trying to place form data into a database. every single request.form() has a blue underline with the error:

Overload resolution failed because no accessible 'item' can be called with these arguments:
'Public readonly default property Item(index as integer) As String': Value of type System.Web.UI.WebControls.TextBox' cannot be converted to Integer'.
'Public Default Propert Item(name As String) As String': Value of type'Sestem.Web.UI.WebControls.TextBox' cannot be converted o 'String'.

I'm not sure if I'm supposed to have a response.write wrapped around all the Request.form's but even when I added those in it gave me this error. Does anyone see the problem?

Dim sql As String = "INSERT INTO users(username,fname,lname,password,address,city,state,zip,country,phone,fax,email,camera,website) values('" & Request.Form(firmName) & "', '" & Request.Form(fName) & "', '" & Request.Form(lName) & "', '" & Request.Form(password) & "', '" & Request.Form(address) & "', '" & Request.Form(city) & "', '" & Request.Form(state) & "', '" & Request.Form(zip) & "', '" & Request.Form(country) & "', '" & Request.Form(phone) & "', '" & Request.Form(fax) & "', '" & Request.Form(email) & "', '" & Request.Form(camera) & "', '" & Request.Form(website) & "');"


Is This A Good Question/Topic? 0

Replies To: No accessible 'item' can be called with these arguments

#2 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 08:00 AM

Blah, hello Monday morning. Maybe I should put quotes around my parameters.
Was This Post Helpful? 0

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 08:04 AM

If this is for a SQL Server database, that is horrible implementation. You are opening yourself up for SQL Injection.

You should use parameterized queries or stored procedures.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 08:42 AM

It's OleDB but I doubt that gives me any more protection. I wasn't taught any security in school so thank you for bringing this to my attention.

I am new to parametrized queries so my only question is where does my with statement go?

Also, is there any kind of necessary security when just reading from a db?
Was This Post Helpful? 0

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 09:05 AM

just a quick example(in C#) of a parameterized query..

using (SqlConnection cn = new SqlConnection(myConnectionString)
{
    using (SqlCommand cmd = cn.CreateCommand())
    {
         // this code should be nearly identical for VB.Net(excluding the semicolons)
         cmd.CommandText = "INSERT INTO Users(UserName, FName, LName) VALUES (@UserName, @FName, @LName)";
         
         cmd.Parameters.AddWithValue("@UserName", Request.Form["firmname"]);
         cmd.Parameters.AddWithValue("@UserName", Request.Form["fname"]);
         cmd.Parameters.AddWithValue("@UserName", Request.Form["lname"]);

         cn.Open();
 
         cmd.ExecuteNonQuery();
    }
}



You should NEVER use concatenated text with a sql query in any command(Update, Select, or Delete) when taking data from the user. Anytime you communicate with the database, you should use parameterized queries or stored procedures.

If you are doing a sql query where you aren't taking inputted data from a user, then you don't have to use a stored procedure or parameterized queries.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 09:38 AM

I am using VB and here is what I have so far:

                Dim sql As String = "INSERT INTO users(username,fname,lname,password,address,city,state,zip,country,phone,fax,email,camera,website) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
                Dim cmd As New OleDbCommand(sql)
                cmd.Parameters.AddWithValue("@firmName", firmName.Text)
                cmd.Parameters.AddWithValue("@fName", fName.Text)
                cmd.Parameters.AddWithValue("@lName", lName.Text)
                cmd.Parameters.AddWithValue("@password", password.Text)
                cmd.Parameters.AddWithValue("@address", address.Text)
                cmd.Parameters.AddWithValue("@city", city.Text)
                cmd.Parameters.AddWithValue("@state", state.Text)
                cmd.Parameters.AddWithValue("@zip", zip.Text)
                cmd.Parameters.AddWithValue("@country", country.Text)
                cmd.Parameters.AddWithValue("@phone", phone.Text)
                cmd.Parameters.AddWithValue("@fax", faxStr)
                cmd.Parameters.AddWithValue("@email", email.Text)
                cmd.Parameters.AddWithValue("@camera", cameraStr)
                cmd.Parameters.AddWithValue("@website", websiteStr)


I'm getting the error: 'AddWithValue' is not a member of 'System.Data.OleDb.OleDbParameterCollection'.
Was This Post Helpful? 0

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 09:42 AM

what version of .Net are you using? It's been there since .Net 2.0.

http://msdn.microsof...dwithvalue.aspx
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 09:55 AM

You mean like what version is installed with my IIS or on my computer? I'd have to ask if it's with IIS but I'm not sure how to find out if it's on my computer.
Was This Post Helpful? 0

#9 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 11:21 AM

If your error is a build error, then you need to check what you have installed on your computer. You can go into Add/Remove Programs to see....

Attached Image

You should also check to see what the project is building against...

Right-click on your project --> Properties --> Application tab....

Attached Image
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 11:55 AM

both are 4
Was This Post Helpful? 0

#11 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No accessible 'item' can be called with these arguments

Posted 16 August 2010 - 11:57 AM

I am not sure what to tell you then. That method is definitely there in .Net 4.
Was This Post Helpful? 0
  • +
  • -

#12 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: No accessible 'item' can be called with these arguments

Posted 17 August 2010 - 07:09 AM

Seems like you copy/pasted some code that was meant to be used with the SqlCommand.Parameters instead of the OleDbCommand.Parameters. As you can see (by following the links), the OleDb.OledbParametersCollection does not have a member/method called "AddWithValue" (however the SQLCommand.Parameters collection does).


Edit: Try using one of the Add methods available to add the Parameter and then on the next line set the value for that parameter using the Item("key") property.

-Frinny

This post has been edited by Frinavale: 17 August 2010 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#13 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: No accessible 'item' can be called with these arguments

Posted 17 August 2010 - 07:30 AM

Actually the AddWithValue method exists for both Sql and OleDb objects.

I think you just missed it on the MSDN page.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#14 Guest_Guest*


Reputation:

Re: No accessible 'item' can be called with these arguments

Posted 17 August 2010 - 08:45 AM

I may have confused you. I am getting an error with my browser, not in visual studio. So the only asp.net version that matters is the one on IIS. I asked and it was earlier than 2.0 so I had them bump it up. I'm going to re-implement that code soon here and I'll let you know if it all goes smooth for me.

Thanks again for all the help.
Was This Post Helpful? 0

#15 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: No accessible 'item' can be called with these arguments

Posted 17 August 2010 - 09:11 AM

Well if it was pre 2.0 then that certainly explains the problem.

Once you get 2.0 or later installed on the machine it shouldn't give you any further problems related to that issue.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2