Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\user\Documents\Data.mfd.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(" Select Count (*) from emp_log where USER ID ='" + textBox1.Text + "'and PASSWORD = '" + textBox2.Text + "'", con);

DataTable dt = new DataTable();

sda.Fill(dt);(in this line my problem was while debbing the code an sqlexception was unhandled and invalid object emp_log was commingcan u help meto slove this )
con.Close();

if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
main ss = new main();
ss.Show();

}

else
{
MessageBox.Show("please check your user id or password");
}


}


}
}
Posted

1 solution

make sure that the table emp_log exists in your db.if not create it and try.
validate your connection string with this[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900