Beispiel #1
0
        public DataSet GetDataQuery(string commandBegin, SQLVarContainer variable, string commandEnd)
        {
            ClearError();
            DataSet ds = new DataSet();
            // build command
            string sqlCommand = "";

            // add command prefix
            sqlCommand += commandBegin + " ";
            // add command variables

            // if  the last variable don't add comma
            sqlCommand += variable.variableName;

            sqlCommand += " " + commandEnd;
            // make connection with compiled connection
            SqlConnection sc = new System.Data.SqlClient.SqlConnection(compiledSqlConnection);


            using (sc)
            {
                sc.Open();
                // create command
                SqlCommand scom = new SqlCommand(sqlCommand, sc);
                using (scom)
                {
                    // add  varaible types

                    scom.Parameters.Add(variable.variableName, variable.type);
                    // set value
                    scom.Parameters[variable.variableName].Value = variable.value;

                    SqlDataAdapter dataAdapter = new SqlDataAdapter(scom);
                    try
                    {
                        dataAdapter.Fill(ds);
                    }
                    catch (Exception e)
                    {
                        error = e.ToString();
                    }
                }
                scom.Dispose();
                sc.Close();
            }
            command_out = sqlCommand;
            return(ds);
        }
Beispiel #2
0
        public void SetDataQuery(string commandBegin, SQLVarContainer variable, string commandEnd)
        {
            ClearError();
            // build command
            string sqlCommand = "";

            // add command prefix
            sqlCommand += commandBegin + " ";
            // add command variables


            sqlCommand += variable.variableName;

            sqlCommand += " " + commandEnd;
            // make connection with compiled connection
            SqlConnection sc = new System.Data.SqlClient.SqlConnection(compiledSqlConnection);


            using (sc)
            {
                sc.Open();
                // create command
                SqlCommand scom = new SqlCommand(sqlCommand, sc);
                using (scom)
                {
                    // add  varaible types

                    scom.Parameters.Add(variable.variableName, variable.type);
                    // set value
                    scom.Parameters[variable.variableName].Value = variable.value;



                    scom.ExecuteNonQuery();
                }
                scom.Dispose();
                sc.Close();
            }
            command_out = sqlCommand;
        }