Eu estou desenvolvendo uma aplicação e gostaria de saber, se é possível fazer um cadastro onde que o usuário cadastre e depois ele loga com o usuário cadastrado.
Se precisar segue o código, se tiver certo:
Este é do formulário de login.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Sistema_e_Learning_Advanced_Plus { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void lblCad_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { CadastroUsuario cser = new CadastroUsuario(); cser.Show(); } private void btnAcessa_Click(object sender, EventArgs e) { frmPrincipal princ = new frmPrincipal(); SqlConnection con = new SqlConnection("Data Source = Nome-PC\\SQLEXPRESS; Initial Catalog = table; Integrated Security = true;"); SqlDataAdapter da = new SqlDataAdapter("SELECT Usuario, Senha FROM dbo.CadUser", con); con.Open(); if (txtUser.Text == "") { da.SelectCommand.CommandText = txtUser.Text; } else if (txtPass.Text == "") { da.SelectCommand.CommandText = txtPass.Text; } else { MessageBox.Show("Bem Vindo Usuário."); } } } }
este é do cadastro de usuários.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Sistema_e_Learning_Advanced_Plus { public partial class CadastroUsuario : Form { public CadastroUsuario() { InitializeComponent(); } private void btnCad_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source = Nome-PC\\SQLEXPRESS; Initial Catalog = table; Integrated Security = true;"); SqlCommand cmd = new SqlCommand("INSERT INTO dbo.CadUser VALUES(@usuario, @Senha)", con); con.Open(); try { cmd.Parameters.AddWithValue("@Usuario", txtUser.Text); cmd.Parameters.AddWithValue("@Senha", txtPass.Text); } catch (SqlException ex) { MessageBox.Show("Usuário e/ou Senha Incorreta!" + ex); } finally { cmd.ExecuteNonQuery(); con.Close(); } } } }
Obrigado pela atenção.