不确定我需要在这里做什么......我有一个SqlCommand
有效的 SQL 语句:
SqlCommand cmd = new SqlCommand("select * from fb_results where fb_date between '20130501' and '20130629' and fb_response = 'Yes' Order by fb_date, fb_login", conn);
现在我想用一个查询字符串参数代替硬编码的日期。
这是我的代码:
string arg1 = Request.QueryString["date1"];
string arg2 = Request.QueryString["date2"];
DateTime dt1 = Convert.ToDateTime(arg1);
DateTime dt2 = Convert.ToDateTime(arg2);
string cvt1 = "'"+dt1.Year.ToString() + dt1.Month.ToString() + dt1.Day.ToString()+"'";
string cvt2 = "'"+dt2.Year.ToString() + dt2.Month.ToString() + dt2.Day.ToString()+"'";
string qry = "select * from fb_results where fb_date between " + cvt1 + " and " + cvt2;
SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("feedback"));
SqlCommand cmd = new SqlCommand(qry, conn);
//SqlCommand cmd = new SqlCommand("select * from fb_results where fb_date between '20130501' and '20130629' and fb_response = 'Yes' Order by fb_date, fb_login", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
我收到一个错误
从字符串转换日期和/或时间时转换失败。
我能做些什么来纠正这个问题?感谢您提供任何帮助。问候,