B
Booney440
Guest
I have a winform I click a menu strip to open a new form to add new user and passwords. when I type the password to open the datagridview only one record is displayed. I still have to finish writing the add new user. but until then i need to correct the datagridview issue.
Any help would be greatly appreciated.
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.SQLite;
namespace Login_Form_SQLITE
{
public partial class New_User : Form
{
public New_User()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtUser.Text.Trim() == "" && txtPassword.Text.Trim() == "")
{
MessageBox.Show("Empty Field");
}
else
{
string query = "SELECT * FROM people WHERE UserName= @user AND Password= @password"; // wrong statment?
SQLiteConnection conn = new SQLiteConnection("Data Source=Login.db;Version=3;");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(query, conn);
cmd.Parameters.AddWithValue("user", txtUser.Text);
cmd.Parameters.AddWithValue("Password", txtPassword.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt; // only shows one line of data
if (dt.Rows.Count > 0)
{
MessageBox.Show("You're Logged in", "Login Successful");
}
}
}
private void New_User_Load(object sender, EventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtNew_User.Text == string.Empty || txtPassword.Text == string.Empty)
{
MessageBox.Show("Please insert name");
}
{
string query = "insert into people (UserName,Password) values ('" + txtUser.Text + "', '" + txtPassword.Text + "')";
// "values('" + txtNew_User.Text + "', '" + txtPassword.Text + "')";
SQLiteConnection conn = new SQLiteConnection("Data Source=Login.db;Version=3;");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(query, conn);
cmd.Parameters.AddWithValue("user", txtUser.Text);
cmd.Parameters.AddWithValue("Password", txtPassword.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
}
}
}
}
Booney440
Continue reading...
Any help would be greatly appreciated.
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.SQLite;
namespace Login_Form_SQLITE
{
public partial class New_User : Form
{
public New_User()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtUser.Text.Trim() == "" && txtPassword.Text.Trim() == "")
{
MessageBox.Show("Empty Field");
}
else
{
string query = "SELECT * FROM people WHERE UserName= @user AND Password= @password"; // wrong statment?
SQLiteConnection conn = new SQLiteConnection("Data Source=Login.db;Version=3;");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(query, conn);
cmd.Parameters.AddWithValue("user", txtUser.Text);
cmd.Parameters.AddWithValue("Password", txtPassword.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt; // only shows one line of data
if (dt.Rows.Count > 0)
{
MessageBox.Show("You're Logged in", "Login Successful");
}
}
}
private void New_User_Load(object sender, EventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtNew_User.Text == string.Empty || txtPassword.Text == string.Empty)
{
MessageBox.Show("Please insert name");
}
{
string query = "insert into people (UserName,Password) values ('" + txtUser.Text + "', '" + txtPassword.Text + "')";
// "values('" + txtNew_User.Text + "', '" + txtPassword.Text + "')";
SQLiteConnection conn = new SQLiteConnection("Data Source=Login.db;Version=3;");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(query, conn);
cmd.Parameters.AddWithValue("user", txtUser.Text);
cmd.Parameters.AddWithValue("Password", txtPassword.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
}
}
}
}
Booney440
Continue reading...