Home All Groups Group Topic Archive Search About

Sql Parameter not found error

Author
22 Feb 2006 4:21 PM
Jim H
Learning ADO.NET is proving to be difficult. 

The last statement below produces the error indicated right
above it (Parameter not found) -- and I have no ideal as to
why.  The Count Property for the Parameters Collection
contains 1.  What am I overlooking?

// -- Code Block --------------------------------------------------
// Define sqlDataAdapter3
System.Data.SqlClient.SqlDataAdapter  sqlDataAdapter3;    

// Define sqlSelectCommend3
   System.Data.SqlClient.SqlCommand      sqlSelectCommand3;  

// Create object sqlDataAdapter3
sqlDataAdapter3   = new System.Data.SqlClient.SqlDataAdapter(); 

// Create object sqlSelectCommand3
sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand();     

// Load the desired sql text command into sqlSelectCommand3
sqlSelectCommand3.CommandText = "SELECT FNXApplication, FNXOriginalName, " +
       "FNXSource, FNXNewName, FNXComment FROM " +
       "FieldNameXRef WHERE (FNXApplication = @FNXApplication)";

// Add one parameter (FNXApplication) to sqlSelectCommand3   <=== Parameter Added
sqlSelectCommand3.Parameters.Add( new System.Data.SqlClient.SqlParameter(
  "@FNXApplication", System.Data.SqlDbType.VarChar, 5, "FNXApplication" ));

// Tell sqlDataAdapter3 to use sqlSelectCommand3 as it's SELECT Command
sqlDataAdapter3.SelectCommand = sqlSelectCommand3;  

// Produces Error: An SqlParameter with ParameterName 'FNXApplication' is  <=== Error
//                 not contained by this SqlParameterCollection.
sqlDataAdapter3.SelectCommand.Parameters["FNXApplication"].Value = selectedApp;
// -- End Code Block ----------------------------------------------

Author
22 Feb 2006 5:05 PM
Mohammad Samara
What if you replace adding the parameter to:

// Add one parameter (FNXApplication) to sqlSelectCommand3   <===
Parameter Added
sqlSelectCommand3.Parameters.Add("@FNXApplication",
System.Data.SqlDbType.VarChar, 5, "FNXApplication" ));

Does this give you the same error?

Mohamamd.
Author
22 Feb 2006 5:06 PM
vinu
Hi  Jim,

Simple mistake, see the highlighted
The parameter name you created with the bellow statement is @FNXApplication

sqlSelectCommand3.Parameters.Add( new System.Data.SqlClient.SqlParameter("@FNXApplication", System.Data.SqlDbType.VarChar, 5, "FNXApplication" ));

but while passing the value you missing you using FNXApplication, missing @

Cheers
Vinu


Show quote
"Jim H" <nore***@BellSouth.net> wrote in message news:MPG.1e66591658eb4281989873@msnews.microsoft.com...
> Learning ADO.NET is proving to be difficult. 
>
> The last statement below produces the error indicated right
> above it (Parameter not found) -- and I have no ideal as to
> why.  The Count Property for the Parameters Collection
> contains 1.  What am I overlooking?
>
> // -- Code Block --------------------------------------------------
> // Define sqlDataAdapter3
> System.Data.SqlClient.SqlDataAdapter  sqlDataAdapter3;    
>
> // Define sqlSelectCommend3
>   System.Data.SqlClient.SqlCommand      sqlSelectCommand3;  
>
> // Create object sqlDataAdapter3
> sqlDataAdapter3   = new System.Data.SqlClient.SqlDataAdapter(); 
>
> // Create object sqlSelectCommand3
> sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand();     
>
> // Load the desired sql text command into sqlSelectCommand3
> sqlSelectCommand3.CommandText = "SELECT FNXApplication, FNXOriginalName, " +
>       "FNXSource, FNXNewName, FNXComment FROM " +
>       "FieldNameXRef WHERE (FNXApplication = @FNXApplication)";
>
> // Add one parameter (FNXApplication) to sqlSelectCommand3   <=== Parameter Added

> sqlSelectCommand3.Parameters.Add( new System.Data.SqlClient.SqlParameter(
>  "@FNXApplication", System.Data.SqlDbType.VarChar, 5, "FNXApplication" ));
>
> // Tell sqlDataAdapter3 to use sqlSelectCommand3 as it's SELECT Command
> sqlDataAdapter3.SelectCommand = sqlSelectCommand3;  
>
> // Produces Error: An SqlParameter with ParameterName 'FNXApplication' is  <=== Error
> //                 not contained by this SqlParameterCollection.

> sqlDataAdapter3.SelectCommand.Parameters["FNXApplication"].Value = selectedApp;

change the above code
to
sqlDataAdapter3.SelectCommand.Parameters["@FNXApplication"].Value = selectedApp;



Show quote
> // -- End Code Block ----------------------------------------------
Author
22 Feb 2006 5:20 PM
Mohammad Samara
Vinu,

"FNXApplication" in the 4th position is a the name of the source
column, it has nothing to do with the parameter.
Author
22 Feb 2006 5:22 PM
Mohammad Samara
Err, thats the last line you are talking about, not parameter add line.
Show quote
:)

AddThis Social Bookmark Button