Exemplo n.º 1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Inicio.Conect Rodar = new Inicio.Conect();

                string strSql = @"insert Prestador ( RazaoSocial, CNPJ , IM  , CnaeId  , Municipio)
                values ( " + "'" + RazaoSocial.Text + "'"
                                + "," + CNPJ.Text
                                + "," + IM.Text
                                + "," + CNAE.Text
                                + "," + CodIBGE.Text + ")";

                SqlCommand comando = new SqlCommand(strSql);

                comando.Connection = Rodar.conectar();

                comando.ExecuteNonQuery();

                if (comando.NotificationAutoEnlist)
                {
                    MessageBox.Show("Cadastro incluído com sucesso");
                }

                Rodar.Fechar();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Os campos não podem estar em branco ou com dados inválidos \n" + exception.Message);
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Inicio.Conect Rodar = new Inicio.Conect();

                /* SELECT   select * from Prestador where
                 *                                          RazaoSocial =  'SÃO PAULO'
                 *                                          OR CNPJ = '12.945.116/0001-82'
                 *                                          OR IM = '8'
                 *                                          OR CnaeId = '77777'
                 *                                          OR Municipio = '12334'   */

                string strSql = @"select  * from Prestador were  
                                        RazaoSocial =" + RazaoSocial.Text
                                + "OR CNPJ =" + CNPJ.Text
                                + " OR IM =" + IM.Text
                                + "OR CnaeId =" + CNAE.Text
                                + "OR Municipio =" + CodIBGE.Text;

                SqlCommand comando = new SqlCommand(strSql);

                comando.Connection = Rodar.conectar();

                SqlDataReader reader = comando.ExecuteReader();

                Rodar.Fechar();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Os campos não podem estar em branco ou com dados inválidos \n" + exception.Message);
            }
        }
Exemplo n.º 3
0
        private void bntExec_Click(object sender, EventArgs e)
        {
            Inicio.Conect Rodar = new Inicio.Conect();

            SqlCommand comando = new SqlCommand(comandoSQLtexto.Text);

            comando.Connection = Rodar.conectar();

            SqlDataReader reader = comando.ExecuteReader();


            int CountL = 1;
            int CountC = 0;

            while (reader.Read())
            {
                retornoTxt.Text = retornoTxt.Text + CountL.ToString() + " - ";

                while (CountC < reader.VisibleFieldCount)
                {
                    retornoTxt.Text = retornoTxt.Text + reader[CountC].ToString();
                    retornoTxt.Text = retornoTxt.Text + " | ";
                    CountC++;
                }
                retornoTxt.Text = retornoTxt.Text + "\n";
                CountC          = 0;
                CountL++;
            }

            reader.Close();

            Rodar.Fechar();
        }