另外一个问题就是另一个页面里,我想查询该日期下所有结果: string str = System.Configuration.ConfigurationManager.ConnectionStrings["HXConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(str); string sele = "select * from tab_in where bjdate='" + txtBjdate.Text.Trim() + "'"; SqlCommand cmd = new SqlCommand(sele, conn); conn.Open(); int i = Convert.ToInt32(cmd.ExecuteScalar()); if (i > 0) 得到的总是“从字符串转换日期和/或时间时,转换失败”。什么原因?怎么改? 请高手指点~~
------解决方案--------------------
string sele = "select * from tab_in where bjdate='" + txtBjdate.Text.Trim() + "'";
处理一下
首先你输入的要是时间格式
string sele = "select * from tab_in where bjdate='" + DateTime.Parse(txtBjdate.Text.Trim()).ToString("yyyy-MM-dd") + " 00:00:00.000'";
------解决方案--------------------