希望高手帮忙改正一下错误,哭ing
需要将用户选择的datetimepicker中的时间保存到数据库来实现和当前时间的对比,然后在保存的时间和当前时间差值为0或负数的时候将数据读出并发送符合时间条件的邮件。
写的逻辑有点儿乱,哭ing 因为真的是弄不清楚。。。
多谢大家了!!!!
private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt=DateTime.Now ;
string now = dt.ToShortDateString();
DateTime dp = dateTimePicker1.Value;
string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\毕业设计\sendmail system\WindowsApplication1\WindowsApplication1\Database2.mdf;Integrated Security=True;User Instance=True";
string mysql = "select * from Table2 where date='" + dateTimePicker1.Value.ToString() + "'";
string mysql = "select * from Table2";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(mysql, conn);
DataSet ds = new DataSet();
adp.Fill(ds, "Table2");
TimeSpan ts = dp.Subtract(dt);
string d = ds.Tables["Table2"].Rows[0][0].ToString();
string r = ds.Tables["Table2"].Rows[0][1].ToString();
string s = ds.Tables["Table2"].Rows[0][2].ToString();
string m = ds.Tables["Table2"].Rows[0][3].ToString();
MessageBox.Show(r);
int i = Convert.ToInt32(ts);
if (i<= 0)
{
MailAddress from = new MailAddress(textBoxUserName.Text);
MailAddress to = new MailAddress(r);
MailMessage message = new MailMessage(from, to);
message.Subject = s;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Body = m;
message.BodyEncoding = System.Text.Encoding.UTF8;
}
}
3 个解决方案
#1
//没仔细看你要实现什么功能,但是
int i = Convert.ToInt32(ts);
//不能这样用,如果你要用,可以用下面的值来进行判断
long l = ts.Ticks;
#2
不懂,帮楼主顶贴了。
#3
string mysql = "select * from Table2 where date='" + dateTimePicker1.Value.ToString() + "'";
就是上面那句吧,
你试试下面代码:
string str = Convert.Tostring(dateTimePicker1.Value);
string mysql = "select * from Table2 where date='" + str + "'";
就是上面那句吧,
你试试下面代码:
string str = Convert.Tostring(dateTimePicker1.Value);
string mysql = "select * from Table2 where date='" + str + "'";
#1
//没仔细看你要实现什么功能,但是
int i = Convert.ToInt32(ts);
//不能这样用,如果你要用,可以用下面的值来进行判断
long l = ts.Ticks;
#2
不懂,帮楼主顶贴了。
#3
string mysql = "select * from Table2 where date='" + dateTimePicker1.Value.ToString() + "'";
就是上面那句吧,
你试试下面代码:
string str = Convert.Tostring(dateTimePicker1.Value);
string mysql = "select * from Table2 where date='" + str + "'";
就是上面那句吧,
你试试下面代码:
string str = Convert.Tostring(dateTimePicker1.Value);
string mysql = "select * from Table2 where date='" + str + "'";