|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sql Parameter not found errorThe 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 ---------------------------------------------- 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. 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... change the above code> 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; to sqlDataAdapter3.SelectCommand.Parameters["@FNXApplication"].Value = selectedApp; Show quote > // -- End Code Block ---------------------------------------------- Vinu,
"FNXApplication" in the 4th position is a the name of the source column, it has nothing to do with the parameter. |
|||||||||||||||||||||||