面对..的异常.从字符串转换日期和/或时间时转换失败. [英] faceing exception as .. Conversion failed when converting date and/or time from character string.

查看:85
本文介绍了面对..的异常.从字符串转换日期和/或时间时转换失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请帮忙..
从字符串转换日期和/或时间时转换失败."




please help with the exception..
"Conversion failed when converting date and/or time from character string."


public void alreadyExists()    // function to check the existing records
    {
        string tdy = DateTime.Now.Date.ToString();
        string aft2dy = DateTime.Now.Date.AddDays(2).ToString();

        string str="select due_date from mConfirm where due_date BETWEEN '"+tdy+"' AND '"+aft2dy+"'";

        sda1 = new SqlDataAdapter(str, cn);
        ds = new DataSet();
        sda1.Fill(ds).ToString();   // HERE I M FACEING THE EXCEPTION

        string d = ds.Tables[0].Rows[0].ItemArray[0].ToString();


        if ((Convert.ToDateTime(d) - DateTime.Today).TotalDays <= 2)
        {
            LblAlreadyExists.Text = "Already Under Process";
        }



    }



谢谢



THANKS

推荐答案

尝试一下:-

try this:-

public void alreadyExists()    // function to check the existing records
{
    string tdy = DateTime.Now.Date.ToString();
    string aft2dy = DateTime.Now.Date.AddDays(2).ToString();

    string str="select due_date from mConfirm where due_date BETWEEN ''"+tdy+"'' AND ''"+aft2dy+"''";

    sda1 = new SqlDataAdapter(str, cn);
    ds = new DataSet();
    sda1.Fill(ds);
    string d ="";
    if(ds!=null && ds.Tables[0].Rows.Count>0)
      d = Convert.ToString(ds.Tables[0].Rows[0].Cells["due_date "]);

    if ((Convert.ToDateTime(d) - DateTime.Today).TotalDays <= 2)
    {
        LblAlreadyExists.Text = "Already Under Process";
    }
}



如果您有帮助,请不要忘记将其标记为答案.

谢谢



Please don''t forget to mark this as your answer if it helps you out.

Thanks


这篇关于面对..的异常.从字符串转换日期和/或时间时转换失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆