i wanted to get the Sign_in and Date columns from the database using the select query but when i run the following code i get an error at the while(dr.Read()).......n the error is "Conversion failed when converting date and/or time from character string."the error is occuring from the while loop onwards......please sumone could tell me where im making a mistake??
following is my code:
private void button1_Click(object sender, EventArgs e){
login lg = new login();
String b = lg.getData();
//DateTime dt = dateTimePicker1.Value;
conn = new SqlConnection(@"Data Source=RAMESH\SQLEXPRESS;Initial Catalog=Payroll;Integrated Security=True");
conn.Open();
string str = "select Sign_in,Date from Attendance where Eno='" +b+ "'and Date='"+dateTimePicker1.Value.Date+"'";
cmd = new SqlCommand(str, conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
MessageBox.Show(dateTimePicker1.Text);
String signin = dr[2].ToString();
DateTime dat = DateTimedr[1];
if ( dat==dateTimePicker1.Value && signin != " ")
{
MessageBox.Show("u have signed in already");
signin_textBox.Clear();
}
else if(dat.ToString()==" " && signin=="")
{
string time = DateTime.Now.ToString("hh:mm:ss tt");
signin_textBox.Text = time;
}
}
dr.Close();
conn.Close();
}