Czesc ucze sie baz danych i nie wiem czemu ciagle wyskakuje mi blad
wykonuje sie else wszystko zrobilem wedlug poradnik a nie moge sie polaczyc z baza danych :(
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 WindowsFormsApp38
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\_mich\Desktop\Data.mdf;Integrated Security=True;Connect Timeout=30;");
sqlConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter("Select Count(*) from users where user='" + textBox1.Text + "' and pass='" + textBox2.Text + "'", sqlConnection);
DataTable dt = new DataTable();
adapter.Fill(dt);
if(dt.Rows[0][0].ToString() == "1")
{
MessageBox.Show("Udalo sie");
}
else
{
MessageBox.Show(" Nie Udalo sie");
}
}
}
}
Utworzylem baze danych itabele
i dodalem do nich wartosci