Connection error during login : The Error is throwing the else statement in the code

  • Thread starter Thread starter mcfee12345
  • Start date Start date
M

mcfee12345

Guest
I am trying to use a code from a template I got .Now each time I try to login the else statement in the code is thrown.

What could be the problem ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;
using System.Windows.Forms;


namespace LeaveManagementSystem1._1
{
class SQLConfig
{

private MySqlConnection con = new MySqlConnection("server=localhost;user id=root;Rivers123*#=;database=db_leave;sslMode=none");
private MySqlCommand cmd;
private MySqlDataAdapter da;
public DataTable dt;
int result;
usableFunction funct = new usableFunction();
public void Execute_CUD(string sql, string msg_false, string msg_true)
{
try
{
con.Open();
cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();

if(result > 0)
{
MessageBox.Show(msg_true);
}
else
{
MessageBox.Show(msg_false);
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
public void Execute_Query(string sql)
{
try
{
con.Open();
cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
public void Load_DTG(string sql,DataGridView dtg)
{
try
{
//con.Open();
if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);
dtg.DataSource = dt;


funct.ResponsiveDtg(dtg);
dtg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dtg.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;




}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}

}

public void Load_ResultList(string sql, DataGridView dtg)
{
try
{
//con.Open();
if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);
dtg.DataSource = dt;


funct.ResponsiveDtg(dtg);
dtg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dtg.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;




}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}

}
public void fiil_CBO(string sql, ComboBox cbo)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}

cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

cbo.DataSource = dt;
cbo.ValueMember = dt.Columns[0].ColumnName;
cbo.DisplayMember = dt.Columns[1].ColumnName;


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}

}
public void combo(string sql, ComboBox cbo)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}

cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

cbo.Items.Clear();
cbo.Text = "Select";
foreach(DataRow r in dt.Rows)
{
cbo.Items.Add(r.Field<string>(0));
}


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}

}
public void singleResult(string sql)

{
try
{
con.Open();
if (con.State == ConnectionState.Open)
{
con.Close();
}
else
{
con.Open();
}
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}
}
public int maxrow(string sql)

{
int maxrow = 0;
try
{
con.Open();
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

maxrow = dt.Rows.Count;


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}
return maxrow;
}
public void loadReports(string sql)

{
try
{
con.Open();
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}

public void autocomplete(string sql,TextBox txt)
{
try
{
con.Open();
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

txt.AutoCompleteCustomSource.Clear();
txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txt.AutoCompleteSource = AutoCompleteSource.CustomSource;

foreach (DataRow r in dt.Rows)
{
txt.AutoCompleteCustomSource.Add(r.Field<string>(0));
}


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}

public void autonumber(string AUTOKEY, TextBox txt)
{
try
{

if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = "SELECT concat(`STRT`, `END`) FROM `tblautonumber` WHERE `DESCRIPTION`='" + AUTOKEY + "'";
da.SelectCommand = cmd;
da.Fill(dt);

txt.Text = DateTime.Now.ToString("yyyy") + dt.Rows[0].Field<string>(0);


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}

public void trans_autonumber(string AUTOKEY, Label txt)
{
try
{

if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new MySqlCommand();
da = new MySqlDataAdapter();
dt = new DataTable();


cmd.Connection = con;
cmd.CommandText = "SELECT concat(`STRT`, `END`) FROM `tblautonumber` WHERE `DESCRIPTION`='" + AUTOKEY + "'";
da.SelectCommand = cmd;
da.Fill(dt);

txt.Text = DateTime.Now.ToString("yyyy") + dt.Rows[0].Field<string>(0);


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}
public void update_Autonumber(string id)
{
Execute_Query("UPDATE `tblautonumber` SET `END`=`END`+`INCREMENT` WHERE `DESCRIPTION`='" + id + "'");
}


}
}

ALTER TABLE `tbluser`
MODIFY `user_id` int(30) NOT NULL AUTO_INCREMENT, AUTO_ItbluserNCREMENT=10329;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>

Continue reading...
 
Back
Top