Chidiebere Mgbemena

Chidiebere Mgbemena

  • NA
  • 179
  • 14.2k

Having problem connecting to database

Mar 18 2020 8:52 AM
 Please i need help!!!
 
  What can i do?
 
my login form is giving error when i try to login after running the application. Below is the
error message:
 
 
 
My source code:
 
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 Sales_Invoice
{
public partial class frmLogin : Form
{
private object txtUserName;
private object txtPassword;
public frmLogin()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=ABJ-DEVSVR-01\MINTSQL;Initial Catalog=Contacts;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Login where Username='" + txtUserName + "' and Password='" + txtPassword + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Main ss = new Main();
ss.Show();
}
else
{
MessageBox.Show("Please check your Username and Password");
}
}
private void frmLogin_Load(object sender, EventArgs e)
{
}
}
}
 
 

Answers (7)