Conexão com banco Error de Código
Pessoal estou aprendendo .Net e estou tentando fazer um form de login, criei o banco, a tabela, mas acho que ta com erro na conexão, alguem me ajuda? aqui vai o codigo:
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 System.Data.SqlClient;
namespace Login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=c: \users\allan\documents\visual studio 2015\Projects\Login\Login\Data.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from Login where username '" + textBox1.Text + "' and senha ='" + textBox2.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Main ss = new Main();
ss.ShowDialog();
} else
{
MessageBox.Show("Login ou Senha inválidos!");
}
}
}
}Discussão (3)
Carregando comentários...