Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by codigo ( 3 years ago )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace CadastroAluno
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonSalvar_Click(object sender, EventArgs e)
        {
            string ra = textBoxRa.Text;
            string nome = textBoxNome.Text;
            string curso = textBoxCurso.Text;
            string senha = textBoxSenha.Text;

            MySqlConnection con = null;
            MySqlCommand cmd = null;
            try
            {
                con = new MySqlConnection("server=localhost;uid=root;pwd='';database=uninove;UseAffectedRows=true");
                con.Open();
                string sql = $"insert into aluno(nome,curso,senha) values('{nome}','{curso}','{senha}')";
                cmd = new MySqlCommand(sql,con);
                int qtdLinhas = cmd.ExecuteNonQuery();       
                if (qtdLinhas > 0)
                {
                    MessageBox.Show("Dados salvos com sucesso!");
                }
                else
                {
                    throw new Exception();
                }
            }catch(Exception ex)
            {
                MessageBox.Show("Não foi possível salvar");
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }
        }
    }
}

 

Revise this Paste

Children: 126530
Your Name: Code Language: