Tech Off Post

Single Post Permalink

View Thread: Command parameters and SQL syntax errors
  • User profile image

    Your parameters look strange to me. I use the names I want to give them in my commandText, not question marks. But then again I am doing it a lot differt.

    Not sure if it will help, but here is how I do it in c$ on a page where our IT Pros will request our Vista MAK for systems that will not be on the network enough to use our KMS server:

    SqlCommand sc = _sql.CreateCommand();
    sc.CommandText =
      "VALUES (@PawPrint, @MachineName, @IP, @ClientID, @Result);";
    sc.Parameters.Add("@PawPrint", SqlDbType.VarChar, PawPrint.Length).Value = PawPrint;
    sc.Parameters.Add("@MachineName", SqlDbType.VarChar, MachineName.Length).Value = MachineName;
    sc.Parameters.Add("@IP", SqlDbType.VarChar, RemoteIP.Length).Value = RemoteIP;
    sc.Parameters.Add("@ClientID", SqlDbType.VarChar, ClientID.Length).Value = ClientID;
    sc.Parameters.Add("@Result", SqlDbType.VarChar, ResultMessage.Length).Value = ResultMessage;