I have an attendancesheet program. I have triple checked my database tables all of their columns are null. I said if they are not null go through but although all of them are null it goes through them all :D I dont know whats wrong
private void textBoxX1_KeyDown(object sender, KeyEventArgs e)
{
sqlcon.Close();
sqlcon.Open();
if (e.KeyCode == Keys.Enter)
{
string t = lbl_Time.Text;
string d = lbl_Date.Text;
string selectQueryName = "SELECT name FROM tbl_attendanceMembers where memberCode=" + "'" + textBoxX1.Text + "'";
var sqlcmdName = new SqlCommand(selectQueryName, sqlcon);
var resultName = sqlcmdName.ExecuteScalar();
string selectQueryId = "SELECT MAX(id) FROM tbl_attendanceSheet";
var sqlcmdId = new SqlCommand(selectQueryId, sqlcon);
var resultId = sqlcmdId.ExecuteScalar();
(1)if (resultId != null)
{
string selectQueryCockin = "SELECT Clockin FROM tbl_attendanceSheet where id=" + resultId;
var sqlcmdCockin = new SqlCommand(selectQueryCockin, sqlcon);
var resultCockin = sqlcmdId.ExecuteScalar();
(2)if (resultCockin != null)
{
(3)if (resultName != null)
{
this.lbl_mmbrname.Text = resultName.ToString();
this.lbl_timestored.Text = t;
textBoxX1.Clear();
}
}
}
else //if result id == null
{
sqlcon.Open();
SqlCommand sqlcmdClockin = new SqlCommand("InputClockIn", sqlcon);
sqlcmdClockin.CommandType = CommandType.StoredProcedure;
sqlcmdClockin.Parameters.AddWithValue("@InputDate", d);
sqlcmdClockin.Parameters.AddWithValue("@InputTime", t);
sqlcmdClockin.ExecuteNonQuery();
SqlDataAdapter sqlda = new SqlDataAdapter("SELECT * FROM tbl_attendanceMembers", sqlcon);
DataTable dt = new DataTable();
sqlda.Fill(dt);
dataGridView1.DataSource = dt;
}
sqlcon.Close();
}
when I execute this code,it equals lbl_mmbrname.Text to resultName and lbl_timestored.Text = t. so it means it has gone through all the way down into the 3rd if statement which is false... I have check it via break poits(f9).
by the first sqlcon.close(); is because if I dont write it it will say connection is not closed which doesnt make sense to me because i have written a sqlcon.close(); down there...
Aucun commentaire:
Enregistrer un commentaire