开发者

How to ignore all other database parameters when retrieving one database parameter

I created a simple code that retrieves a database parameter which is ("SOPNUMBE", ordernumber) However, sometimes an employee will fill out an incorrect order giving me a "LIFTxxxx" value instead of a SOPNUMBE which is "ORDxxxxx" etc. Since L is before S, my ftp site processes LIFT first creating an error. I would really like to have this application ignore everything besides "SOPNUMBE", I feel this is a pretty simple question and to me it sounds like a simple if then statement. But I am having trouble wording it. Any help would be greatly appreciated!!

public bool UpdateOrderToShipped(string order)
{
    orderNumber = order;
    string batch = ConfigurationManager.AppSettings["SuccessfulOrderBatch"];
    string statement = "UPDATE SOP10100 SET BACHNU开发者_运维知识库MB = '"+ batch +"' WHERE SOPNUMBE = @SOPNUMBE";
    SqlCommand comm = new SqlCommand(statement, connectionPCI);
    comm.Parameters.Add("SOPNUMBE", orderNumber);
    try
    {
        comm.Connection.Open();
        comm.ExecuteNonQuery();
        comm.Connection.Close();
    }
    catch(Exception e)
    {
        comm.Connection.Close();
        KaplanFTP.errorMsg = "Database error: " + e.Message;
    }
    statement = "SELECT SOPTYPE FROM SOP10100 WHERE SOPNUMBE = @SOPNUMBE";
    comm.CommandText = statement;
    SqlDataAdapter da = new SqlDataAdapter(comm);
    DataTable dt = new DataTable();
    da.Fill(dt);
    soptype = dt.Rows[0]["SOPTYPE"].ToString();



    return true;
}


LAs noted in my comment, if you aren't comfortable changing this code with an if statement, then you probably shouldn't be maintaining this code. (Do you know where else this code is referenced? Your change will be affecting those places.)

But here you go...

public bool UpdateOrderToShipped(string order)
{
    if ((String.CompareOrdinal(order, 0, "ORD", 0, 3) == 0)
    {
       orderNumber = order;
       string batch = ConfigurationManager.AppSettings["SuccessfulOrderBatch"];
       string statement = "UPDATE SOP10100 SET BACHNUMB = '"+ batch +"' WHERE SOPNUMBE = @SOPNUMBE";
       SqlCommand comm = new SqlCommand(statement, connectionPCI);
       comm.Parameters.Add("SOPNUMBE", orderNumber);
       try
       {
           comm.Connection.Open();
           comm.ExecuteNonQuery();
           comm.Connection.Close();
       }
       catch(Exception e)
       {
           comm.Connection.Close();
           KaplanFTP.errorMsg = "Database error: " + e.Message;
       }
       statement = "SELECT SOPTYPE FROM SOP10100 WHERE SOPNUMBE = @SOPNUMBE";
       comm.CommandText = statement;
       SqlDataAdapter da = new SqlDataAdapter(comm);
       DataTable dt = new DataTable();
       da.Fill(dt);
       soptype = dt.Rows[0]["SOPTYPE"].ToString();



       return true;
   } else
   {
      return false;
   }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜