Sql inline query with parameters. Parameter is not read when the query is executed

前端 未结 1 485
太阳男子
太阳男子 2020-12-07 06:43

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

相关标签:
1条回答
  • 2020-12-07 06:45

    That is just all kinds of ugly. This could be a lot simpler (even though I'm not sure what SqlHelper does:

    using(SqlConnection conn = new SqlConnection(connString))
    {
        conn.Open();
    
        SqlCommand command = new SqlCommand(InsertStmtUsersTable, conn);
        command.CommandType = CommandType.Text;
    
        command.Parameters.Add(new SqlParameter("username", userNameString));
        command.Parameters.Add(new SqlParameter("password", passwordString));
        command.Parameters.Add(new SqlParameter("email", emailString));
        command.Parameters.Add(new SqlParameter("userTypeId", userTypeId));
        command.Parameters.Add(new SqlParameter("memberId", memberId));
        // Rest of your Parameters here
    
        var result = (int)command.ExecuteScalar();
    }
    
    0 讨论(0)
提交回复
热议问题