Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Muhammad Ali
2k
26
1.9k
how to make this code work .. i want to show leftdays
Jan 28 2017 9:12 PM
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();
}
}
Reply
Answers (
14
)
Pop-Up image in asp.net using C#
HTML Table To Xlsx