Код: Выделить всё
namespace Login
{
public partial class logForm : Form
{
public logForm()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=testData;Integrated Security=True;Encrypt=True;TrustServerCertificate=True");
private void logUser_Click(object sender, EventArgs e)
{
String username, user_password;
username = txt_user.Text;
user_password = txt_pass.Text;
try
{
String query = "SELECT * FROM loginTable WHERE email or username = '"+txt_user.Text+"' AND password = '"+txt_pass.Text+"'";
SqlDataAdapter sda = new SqlDataAdapter(query, con);
DataTable dtable = new DataTable();
sda.Fill(dtable);
if (dtable.Rows.Count > 0) //reads dataTable
{
username = txt_user.Text;
user_password = txt_pass.Text;
Form1 f1 = new Form1(); //opens window after successful login
f1.Show();
this.Hide();
}
else
{
MessageBox.Show("Incorrect login Information, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_user.Clear(); //clears inputs after failure
txt_pass.Clear();
txt_user.Focus();
}
}
catch
{
MessageBox.Show("Error");
}
finally
{
con.Close();
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... name-in-th