Vuk Stanojevic

Vuk Stanojevic

  • 1.2k
  • 140
  • 45.5k

SqlDataAdapter s = new SqlDataAdapter(query, con); DataTable

Feb 27 2018 12:00 PM
Dear all ,
this is my code , it doesn't show any error , builded successfully but it doesn't work when i try to test it :
 
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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\vukst\Documents\users.mdf;Integrated Security=True;Connect Timeout=30;");
string query = "Select Count(*) from ltbl Username = '" + textBox1.Text.Trim() + "' and Password = '" + textBox2.Text.Trim() + " ' ";
SqlDataAdapter s = new SqlDataAdapter(query, con);
DataTable ltbl = new DataTable();
s.Fill(ltbl);
if (ltbl.Rows.Count == 1)
{
this.Hide();
Form2 ss = new Form2();
ss.Show();
}
else
{
MessageBox.Show("Please check your username and password");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
 
It says : ccc
it marks letter s in following 2 rows :
 
SqlDataAdapter s = new SqlDataAdapter(query, con);

s.Fill(ltbl); 

Answers (2)