public partial class LoginForm : Form { private const string connectionString = "ConnectionString"; public LoginForm() { InitializeComponent(); } private void btnLogin_Click(object sender, EventArgs e) { string enteredUsername = txtUsername.Text; string enteredPassword = txtPassword.Text; // Establish a connection to the database using (SqlConnection connection = new SqlConnection(connectionString)) { try { connection.Open(); // Prepare the SQL query to check the entered username and password against the table string query = "SELECT COUNT(*) FROM vijay WHERE username = @Username AND password = @Password"; // Create a SqlCommand object with the query and connection using (SqlCommand command = new SqlCommand(query, connection)) { // Set the parameter values for username and password command.Parameters.AddWithValue("@Username", enteredUsername); command.Parameters.AddWithValue("@Password", enteredPassword); // Execute the query and get the result int result = (int)command.ExecuteScalar(); // Check the result to determine if the login is successful if (result > 0) { MessageBox.Show("Login successful"); } else { MessageBox.Show("Invalid username or password"); } } } catch (Exception ex) { MessageBox.Show("An error occurred: " + ex.Message); } } }