How to set database execute statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirubagari
    New Member
    • Jun 2007
    • 158

    How to set database execute statement

    Hi Expert,
    Kindly highlighten me how to set execute statement in the end of sql,
    Attach is my code
    Code:
         private void InsertintoDB()
            {
    
                string strSQL = "";
    
                string strDBType = System.Configuration.ConfigurationManager.AppSettings["DBType"];
                string strConn = System.Configuration.ConfigurationManager.AppSettings["DB_CONNECTION_STRING1"].ToString();
                string strInsertTableName_Sql = "CIMMGR.[dbo].ANSDATA";
                string strInsertTableName_Ora = "CIMMGR.ANSDATA";
          
    
                if (strDBType == "MSSQL")
                {
                    strSQL = "Insert into " + strInsertTableName_Sql + "(EQID,CHAMBERID,MEMO,MESSAGE,REPORTTIME,PARAMETERID,RULEID,ALGORITHMVALUE,RULENAME,WAFER,ALARMACTION,RUNREUSLT)"
                              + " Values(" + this.m_strEQID + "," + this.m_strChamberID + "," + this.m_strDescription + "," + this.m_strMessageText + "," + this.m_parameterId + "," + this.m_ruleId + "," + this.m_RunResult + "," + this.m_algorithmValue + "," + this.m_ruleName + "," + this.m_wafer + "," + this.m_strAlarmAction + "," + this.m_strProcessID + ")";
    
                   
                }
                else
                {
                    strSQL = "Insert into " + strInsertTableName_Ora + "(EQID,CHAMBERID,MEMO,MESSAGE,REPORTTIME,PARAMETERID,RULEID,ALGORITHMVALUE,RULENAME,WAFER,ALARMACTION,RUNREUSLT)"
                            + " Values(" + this.m_strEQID + "," + this.m_strChamberID + "," + this.m_strDescription + "," + this.m_strMessageText + "," + this.m_parameterId + "," + this.m_ruleId + "," + this.m_RunResult + "," + this.m_algorithmValue + "," + this.m_ruleName + "," + this.m_wafer + "," + this.m_strAlarmAction + "," + this.m_strProcessID + ")";
                    
    
                this.logger.LogMsg(@"[ANS] InsertIntoDB", true);
                this.logger.LogMsg(@"[ANS] [SQL]: Insert into " + strInsertTableName_Ora + "(EQID,CHAMBERID,MEMO,MESSAGE,REPORTIME,PARAMETERID,RULEID,ALGORITHMVALUE,RULENAME,WAFER,ALARMACTION,VIEWEVENT)" + " Values(" + this.m_strEQID + "," + this.m_strChamberID + "," + this.m_strDescription + "," + this.m_strMessageText + "," + this.m_parameterId + "," + this.m_ruleId + "," + this.m_RunResult + "," + this.m_algorithmValue + "," + this.m_ruleName + "," + this.m_wafer + "," + this.m_strAlarmAction + "," + this.m_strProcessID + ")",true);
                //return strSQL;
    
                }
    
            }
            //Kiru 1.8.2012 End
            #endregion
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    #2
    check out this link you get complete details

    Last edited by PreethiGowri; Dec 21 '12, 11:02 AM. Reason: misspelled the word

    Comment

    • HosseinKhoddami
      New Member
      • Dec 2012
      • 2

      #3
      use Like this statement

      Code:
      string strQuery = "INSERT INTO Table1(FirstName , LastName , Age) Values ( '{0}' , '{1}' , {2} ) ";
      
      strQuery = string.Format(strQuery , txt_FirstName.Text , txt_LastName.Text , Convert.Toint32(txt_Age.Text));
      
      
      and Ten you can use strCommand in function like DoCommand(strQuery);
      
      
      using system.data.sqlclient; // imports sqlclient on top of your form or class
      
      int DoCommand(string strCommand)
      {
      sqlConnection con = new sqlConnection("your connection string here");
      sqlCommand cmd = new sqlCommand(strCommand , con);
      
      int i = 0;
      con.open();
      i=cmd.executeNonQuery();
      con.close();
      
      return i;
      
      }
      Last edited by PsychoCoder; Dec 25 '12, 07:04 PM. Reason: Added code tags

      Comment

      Working...