Exemple #1
0
        public int SelectExist(string FunctionName, DatabaseAccessObject databaseAccessObject, string cmdText, LoggerObject Log, params System.Data.SqlClient.SqlParameter[] parameterArray)
        {
            string parameterText = "";

            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdText, databaseAccessObject.Connection))
            {
                cmd.Transaction = databaseAccessObject.Transaction;
                if (parameterArray.Length != 0)
                {
                    int parameterCount = 0;
                    foreach (System.Data.SqlClient.SqlParameter parameter in parameterArray)
                    {
                        cmd.Parameters.Add(parameter);
                        if (parameterCount != 0)
                        {
                            parameterText += ",";
                        }
                        parameterText  += parameter.ParameterName + "(" + parameter.SqlDbType + ") = " + parameter.Value;
                        parameterCount += 1;
                    }
                }
                using (System.Data.SqlClient.SqlDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter())
                {
                    DataTable data     = new DataTable();
                    Stopwatch sqlTimer = new Stopwatch();
                    Log.SaveFunctionLog_Start(DateTime.Now, FunctionName, "SQLIN", "", "iLibrary", "", cmd.CommandText, parameterText);
                    sqlTimer.Start();
                    dataAdapter.SelectCommand = cmd;
                    dataAdapter.Fill(data);
                    sqlTimer.Stop();
                    Log.SaveFunctionLog_End(DateTime.Now, 0, FunctionName, "SQLOUT", "", "iLibrary", sqlTimer.ElapsedMilliseconds, "", Log.DataTableToCSV(data), "");
                    return(data.Rows.Count);
                }
            }
        }
Exemple #2
0
 public int OperateData(string FunctionName, DatabaseAccessObject databaseAccessObject, string cmdText, LoggerObject Log, params System.Data.SqlClient.SqlParameter[] parameterArray)
 {
     using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdText, databaseAccessObject.Connection))
     {
         string parameterText = "";
         cmd.Transaction = databaseAccessObject.Transaction;
         if (parameterArray.Length != 0)
         {
             int parameterCount = 0;
             foreach (System.Data.SqlClient.SqlParameter parameter in parameterArray)
             {
                 cmd.Parameters.Add(parameter);
                 if (parameterCount != 0)
                 {
                     parameterText += ",";
                 }
                 parameterText  += parameter.ParameterName + "(" + parameter.SqlDbType + ") = " + parameter.Value;
                 parameterCount += 1;
             }
         }
         Stopwatch sqlTimer = new Stopwatch();
         Log.SaveFunctionLog_Start(DateTime.Now, FunctionName, "SQLIN", "", "iLibrary", "", cmd.CommandText, parameterText);
         sqlTimer.Start();
         int affectedRow = cmd.ExecuteNonQuery();
         sqlTimer.Stop();
         Log.SaveFunctionLog_End(DateTime.Now, 0, FunctionName, "SQLOUT", "", "iLibrary", sqlTimer.ElapsedMilliseconds, "", affectedRow.ToString() + " Records.", "");
         return(affectedRow);
     }
 }
Exemple #3
0
        public System.Data.SqlClient.SqlDataReader SelectDataReader(string FunctionName, DatabaseAccessObject databaseAccessObject, string cmdText, LoggerObject Log, params System.Data.SqlClient.SqlParameter[] parameterArray)
        {
            string parameterText = "";

            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdText, databaseAccessObject.Connection))
            {
                cmd.Transaction = databaseAccessObject.Transaction;
                if (parameterArray.Length != 0)
                {
                    int parameterCount = 0;
                    foreach (System.Data.SqlClient.SqlParameter parameter in parameterArray)
                    {
                        cmd.Parameters.Add(parameter);
                        if (parameterCount != 0)
                        {
                            parameterText += ",";
                        }
                        parameterText  += parameter.ParameterName + "(" + parameter.SqlDbType + ") = " + parameter.Value;
                        parameterCount += 1;
                    }
                }

                Stopwatch sqlTimer = new Stopwatch();

                Log.SaveFunctionLog_Start(DateTime.Now, FunctionName, "SQLIN", "", "iLibrary", "", cmd.CommandText, parameterText);
                sqlTimer.Start();
                System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                sqlTimer.Stop();
                //Log.SaveFunctionLog_End(DateTime.Now, 0, FunctionName, "SQLOUT", "", "iLibrary", sqlTimer.ElapsedMilliseconds, "", Log.ReaderToCSV(reader), "");
                return(reader);
            }
        }
Exemple #4
0
        public DataTable SelectData(string FunctionName, DatabaseAccessObject databaseAccessObject, string cmdText, LoggerObject Log, params System.Data.SqlClient.SqlParameter[] parameterArray)
        {
            string parameterText = "";

            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdText, databaseAccessObject.Connection))
            {
                cmd.Transaction = databaseAccessObject.Transaction;
                if (parameterArray.Length != 0)
                {
                    int parameterCount = 0;
                    foreach (System.Data.SqlClient.SqlParameter parameter in parameterArray)
                    {
                        cmd.Parameters.Add(parameter);
                        if (parameterCount != 0)
                        {
                            parameterText += ",";
                        }
                        parameterText  += parameter.ParameterName + "(" + parameter.SqlDbType + ") = " + parameter.Value;
                        parameterCount += 1;
                    }
                }
                Stopwatch sqlTimer = new Stopwatch();

                Log.SaveFunctionLog_Start(DateTime.Now, FunctionName, "SQLIN", "", "iLibrary", "", cmd.CommandText, parameterText);
                sqlTimer.Start();
                System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
                sqlTimer.Stop();
                //Log.SaveFunctionLog_End(DateTime.Now, 0, FunctionName, "SQLOUT", "", "iLibrary", sqlTimer.ElapsedMilliseconds, "", Log.ReaderToCSV(reader), "");

                DataTable dt = CreateSchemaDataTable(reader);

                // 結果を表示します。
                while (reader.Read())
                {
                    DataRow row = dt.NewRow();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        row[i] = reader.GetValue(i);
                    }
                    dt.Rows.Add(row);
                }
                Log.SaveFunctionLog_End(DateTime.Now, 0, FunctionName, "SQLOUT", "", "iLibrary", sqlTimer.ElapsedMilliseconds, "", Log.ReaderToCSV(dt), "");
                reader.Close();
                return(dt);
            }
        }