SqlConnection myconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\muhammad\my documents\visual studio 2010\Projects\ProjectClock\ProjectClock\ClockDB.mdf;Integrated Security=True;User Instance=True");
private void button1_Click(object sender, EventArgs e)
{
myconnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into employTable(employname,ismarred,salarydate,expiredate) values('" + textBox1.Text + "','" + checkBox1.Checked + "','" + dateTimePicker1.Value.ToString("M/d/yyyy") + "','" + dateTimePicker1.Value.AddDays(365).ToString("M/d/yyyy") + "')";
cmd.Connection = myconnection;
cmd.ExecuteNonQuery();
string selectSql = "select * from employTable";
SqlCommand com = new SqlCommand(selectSql, myconnection);
string first;
string Second;
DateTime salaryDate;
DateTime expireDate;
int daysleft;
////////////////this block of code is not showing the messagebox it dont't gives error ///////////////////////////
using (SqlDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
first = (read["salarydate"].ToString());
Second = (read["expiredate"].ToString());
salaryDate = DateTime.ParseExact(first, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
expireDate = DateTime.ParseExact(Second, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
TimeSpan t1 = expireDate - salaryDate;
daysleft = t1.Days;
MessageBox.Show(daysleft.ToString(), "Days Left");
}
/===================/
}
myconnection.Close();
}
}

Rafnas T PPosted Feb 5, 2017, 11:32 PM
/*========================Updating the daysleft Slot in DataBase ====================*/
Muhammad AliPosted Feb 4, 2017, 5:52 AM
Muhammad AliPosted Feb 4, 2017, 5:06 AM
Rafnas T PPosted Feb 2, 2017, 7:48 AM
/*========================Updating the daysleft Slot in DataBase ====================*/
Nitin SontakkePosted Feb 2, 2017, 6:07 AM
Muhammad AliPosted Feb 2, 2017, 5:45 AM
Code is :
/*========================Updating the daysleft Slot in DataBase ====================*/
Rafnas T PPosted Feb 1, 2017, 4:33 AM
Amit KumarPosted Jan 31, 2017, 12:39 AM
Nitin SontakkePosted Jan 30, 2017, 10:12 PM
Amit GuptaPosted Jan 30, 2017, 9:26 AM
Muhammad AliPosted Jan 30, 2017, 9:04 AM
salaryDate = DateTime.ParseExact(first, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture);
error :String was not recognized as a valid DateTime.
My Datatype of salarydate and expirydate is datetime ..
Bikesh SrivastavaPosted Jan 29, 2017, 10:28 AM
Amit GuptaPosted Jan 29, 2017, 3:49 AM
Nitin SontakkePosted Jan 29, 2017, 12:38 AM