Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views1 page

Excodc#3

The document is a C# code snippet for a login form in a Windows Forms application. It establishes a connection to a SQL Server database to validate user credentials against a 'usuarios' table. If the credentials are valid, it opens a new form; otherwise, it displays an error message.

Uploaded by

Victor Afonso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Excodc#3

The document is a C# code snippet for a login form in a Windows Forms application. It establishes a connection to a SQL Server database to validate user credentials against a 'usuarios' table. If the credentials are valid, it opens a new form; otherwise, it displays an error message.

Uploaded by

Victor Afonso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace bacnodados
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}

private void btnOK_Click(object sender, EventArgs e)


{
string stringConexao = "Data Source=VAIO\\SQLEXPRESS;Initial
Catalog=bd;Integrated Security=True";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = stringConexao;
try
{
cn.Open();
SqlCommand cd = new SqlCommand();
cd.CommandText = "Select * from usuarios Where login like'" +
txtLogin.Text + "' and senha='" + txtSenha.Text + "'";
cd.Connection = cn;

SqlDataReader dr = cd.ExecuteReader();

if (dr.Read())
{
frmMenu m = new frmMenu();
m.Show();
}
else
{
MessageBox.Show("Login ou Senha Inválido !", "Atenção");
}
}
catch (SqlException x)
{
MessageBox.Show(x.Message, "Erro");
}
cn.Close();
}

private void btnSair_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

You might also like