This is new answer:
add following code block in you
Login page
int cntUser = DBHelper.DB.ExecuteScalar("SELECT COUNT (*) FROM [signin] WHERE username='" + txtusername.Text + "' AND password='" + txtpassword.Text + "'");
if (cntUser > 0)
{
frmMain main = new frmMain();
main.Show();
}
else
{
MessageBox.Show("Invalid User Name or Password");
}
add new class file "
clsDBHelper.cs" in your solution
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DBHelper
{
public sealed class DB
{
const string DBConnection = "Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True";
private DB()
{
}
public static OleDbDataReader getDataReader(string strsql)
{
try
{
OleDbConnection con = new OleDbConnection();
con = getConnection();
OleDbCommand cmd = new OleDbCommand(strsql, con);
OleDbDataReader dr = cmd.ExecuteReader();
return dr;
}
catch (Exception ex)
{
MessageBox.Show("Sorry! for inconvenience.\nPlease report following error to imdadhusen.sunasara@gmail.com, If you can see more than once.\n" + ex.Message, "Database Error", MessageBoxButtons.OK);
}
return null;
}
public static DataTable getDataTable(string strsql)
{
try
{
OleDbConnection con = new OleDbConnection();
con = getConnection();
OleDbDataAdapter da = new OleDbDataAdapter(strsql, con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show("Sorry! for inconvenience.\nPlease report following error to imdadhusen.sunasara@gmail.com, If you can see more than once.\n" + ex.Message, "Database Error", MessageBoxButtons.OK);
}
return null;
}
public static int ExecuteNonQuery(string strsql)
{
int isSuccess = 0;
try
{
OleDbConnection con = new OleDbConnection();
con = getConnection();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = strsql;
isSuccess = cmd.ExecuteNonQuery();
closeConnection(con);
}
catch (Exception ex)
{
MessageBox.Show("Sorry! for inconvenience.\nPlease report following error to imdadhusen.sunasara@gmail.com, If you can see more than once.\n" + ex.Message, "Database Error", MessageBoxButtons.OK);
}
return isSuccess;
}
public static int ExecuteScalar(string strsql)
{
int isSuccess = 0;
OleDbConnection con = new OleDbConnection();
con = getConnection();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = strsql;
try
{
isSuccess = Convert.ToInt32(cmd.ExecuteScalar());
}
catch
{
isSuccess = 0;
}
closeConnection(con);
return isSuccess;
}
public static OleDbConnection getConnection()
{
OleDbConnection con = new OleDbConnection();
try
{
string MDBFilePath = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SBSysDB.mdb";
string strcon = DBConnection.Replace("{0}", MDBFilePath);
con = new OleDbConnection(strcon);
if (con.State != ConnectionState.Open) con.Open();
}
catch (Exception ex)
{
MessageBox.Show("Sorry! for inconvenience.\nPlease report following error to imdadhusen.sunasara@gmail.com, If you can see more than once.\n" + ex.Message, "Database Error", MessageBoxButtons.OK);
}
return con;
}
public static void closeConnection(OleDbConnection con)
{
if (con.State == ConnectionState.Open) con.Close();
}
}
}
Please use the above solution and it will working fine.
Please do let me know, if you have any doubt.
Please provide "
Vote":thumbsup: if this would be helpful, and make "
Accept Answer" if this would be correct answer.:rose:
Thanks,
Imdadhusen