SoFunction
Updated on 2025-03-07

Explanation of several ways to execute SQL in C#

1. Different databases

private InfoLightDBTools dbTools;       //#ORACLE#
 = new InfoLightDBTools(clientInfo, dbName);

private InfoLightDBTXTools dbTXTools;  //#ORACLE# To be used in combination with transaction processing: BeginTransaction(), Commit(), Rollback(), EndTransaction()
 = new InfoLightDBTXTools(clientInfo, dbName);

private InfoLightMSTools mdbtool;    //#SQL SERVER#

Execution method in Server

public DataTable GetManPowerData(string vLineName, string vShift)
        {
            DataTable dt = new DataTable();
            ExecutionResult exeRes = new ExecutionResult();
            List<SqlParameter> mParams;
            SqlParameter mLine_NameParam, mDNSParam;
            string sql = @"select *
  from manpower
 where lineid = (select ID
                   from lines
                  where line = @LINENAME
                    AND (SMTCS IS NULL OR SMTCS = 'C'))
   and dns = @dns
 order by time1_start
";


            mParams = new List<SqlParameter>();
            mLine_NameParam = new SqlParameter("@LINENAME", , 20);
            mLine_NameParam.Value = vLineName;
            (mLine_NameParam);

            mDNSParam = new SqlParameter("@dns", , 20);
             = 0;
            (mDNSParam);


            exeRes = (sql, mParams);
            if ()
                dt = ((DataSet)).Tables[0];

            return dt;
        }

Execution method

public DataTable getModel(string line_name)
        {
            DataTable dt = new DataTable();
            ExecutionResult exeRes = new ExecutionResult();
            DBParameter dbParam = new DBParameter();
            string sql = @"   SELECT DISTINCT T.MODEL_NAME
    FROM sfism4.R_LINE_MODEL_STATUS_T t
   WHERE T.LINE_NAME = :line_name
";
            ();
            ("line_name", , line_name);
            exeRes = (sql, ());
            if ()
                dt = ((DataSet)).Tables[0];
            return dt;
        }

4. Perform update operations

public ExecutionResult DoDelete(string sap_plant, string wip_sn, string up_data1)
        {
            ExecutionResult exeRes = new ExecutionResult();
             = "";
            DBParameter dbParam = new DBParameter();
            #region sql
            string sql = @"  DELETE SFISM4.U_UP2INTERFACE_TODOLIST_T A
 WHERE A.CUST_NO = :CUST_NO
   AND  = 'IMS_STOP'
   AND A.JOB_STATUS = 'OK'
   AND A.WIP_SN = :WIP_SN
   AND A.UP_DATA1 = :UP_DATA1
";
            #endregion

            #region Param
            ();
            ("CUST_NO", , sap_plant);
            ("WIP_SN", , wip_sn);
            ("UP_DATA1", , up_data1);
            #endregion
            try
            {
                exeRes = (sql, ());
            }
            catch (Exception ex)
            {
                 += ;
                 = false;
            }
            return exeRes;
        }

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.