I am having a problem with my sql query in c#, basically it's inline query with parameters, but when I run it it tells me that parameter 1 or parameter 2 is not there
here is my query declared on top of the page as public:
public const string InsertStmtUsersTable = "insert into Users (username, password, email, userTypeID, memberID, CM7Register) " +
"Values(@username, @password, @email, @userTypeID, @memberID,@CM7Register ); select @@identity";
this is my code for assigning the parameters, I know I am having problem so I am assigning the params twice:
Username =(cmd.Parameters["@username"].Value = row["username"].ToString()) as string;
cmd.Parameters["@username"].Value = row["username"].ToString();
In 1 methopd it calls this query and tries to insert to table, here is the code:
Result = Convert.ToInt32(SqlHelper.ExecuteScalar(con, CommandType.Text,InsertStmtUsersTable));
Exact error message is: Must declare the variable '@username'.
Could this code be a problem, because all the previous coding is declared with in this using statement, except declaration of query, here the using statement:
using (SqlCommand cmd = new SqlCommand(InsertStmtUsersTable, con))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…