+ Reply to Thread
Results 1 to 4 of 4

Thread: '?companyname' not found in the collection.

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    '?companyname' not found in the collection.

    I have a SPROC in MySQL
    Code:
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `GetCompany` $$
    CREATE PROCEDURE `GetCompany`(
    companyref INT,
    companyname VARCHAR (60)
    )
    BEGIN
    SET @ref = companyref;
    SET @companyname = companyname;
    SELECT
    companies.companyref,
    companies.name,
    companies.web,
    companies.domain,
    companies.dtAdded,
    companies.ipadd,
    companies.addedBy,
    CONCAT(users.forename,' ',users.surname) AS addedByUser
    FROM companies
    LEFT JOIN users ON companies.addedBy=users.userref
    WHERE
    companies.companyref=if(@ref=0,companies.companyref,@ref) AND
    companies.name=if(ISNULL(@companyname),companies.name,@companyname)
    ;
    END $$
    DELIMITER ;
    
    which is called from my .NET code like so.
    Code:
    Dim conn As New MySqlConnection(mybwGlobal.connString)
                Dim mycomm As New MySqlCommand("GetCompany", conn)
                mycomm.CommandType = Data.CommandType.StoredProcedure
                Dim rs As MySqlDataReader
                Using conn
                    Using mycomm
                        Try
                            mycomm.Parameters.Add(New MySqlParameter("companyref", ref))
                            Dim nameP As New MySqlParameter("companyname", MySqlDbType.VarChar)
                            If String.IsNullOrEmpty(name) Then
                                nameP.Value = DBNull.Value
                            Else
                                nameP.Value = name
                            End If
                            conn.Open()
                            rs = mycomm.ExecuteReader
                            If rs.HasRows Then
                                rs.Read()
                                newCompany = New Company(rs("companyref"), rs("name"))
                            End If
                            rs.Close()
    
    However, when it executes I get an error System.ArgumentException: Parameter '?companyname' not found in the collection.

    I just don't understand why it's not working...Any ideas?

  2. #2
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    This error is produced by MySql or .Net?

    May be you need to add this parameter to mycomm

  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by micky View Post
    This error is produced by MySql or .Net?

    May be you need to add this parameter to mycomm
    It's a MySQL error....

    I think you could be right m. I hadn't added in to the command object.
    Needed to add
    Code:
    mycomm.Parameters.Add(nameP)
    
    That seems to have sorted it...Thanks m...

  4. #4
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    cool........ glad i cud help

+ Reply to Thread

Similar Threads

  1. loop through a collection
    By Shem in forum .NET Development
    Replies: 15
    Last Post: October 17th, 2008, 11:54 AM
  2. No Default Member Found for type
    By richyrich in forum .NET Development
    Replies: 5
    Last Post: May 29th, 2008, 02:33 PM
  3. Replies: 0
    Last Post: April 25th, 2008, 07:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO