【问题标题】:Cannot Select Between No error can someonehelp me check string?无法选择之间没有错误有人可以帮我检查字符串吗?
【发布时间】:2015-06-10 03:06:33
【问题描述】:

我想在 textbox1 和 textbox2 中输入日期值,但我认为我不确定字符串 cmd 有人可以帮我检查问题吗?请

   try
        {
            con = new SqlConnection(MyConnectionString);
            con.Open();
            int tp;
            string sqlstr = "select * from viewReC_store where stk_date_time between '" + TextBox1.Text + "' and '" + TextBox2.Text + "'";

            cmd = new SqlCommand(sqlstr, con);
            SqlDataReader sdr = cmd.ExecuteReader();
            GridView1.DataSource = sdr;
            GridView1.DataBind();

        }
        catch (Exception ex)
        {
            Label4.Text = "ERROR"+ex ;
        }
        con.Close();

Blockquote string sqlstr = "select * from viewReC_store where stk_date_time between '" + TextBox1.Text + "' and '" + TextBox2.Text + "'";

我猜这行

【问题讨论】:

  • 你有什么错误吗?
  • 没有任何错误,只是对我不起作用点击 btn
  • 尝试返回 sqlstr 并在 SQL Server 中运行它以查看是否有任何行。
  • 可以在sql server中运行没有任何错误
  • 您已使用text box's 来捕获日期,这可能会导致意外结果,除非date 与SQL 期望的格式不完全相同。尝试将您的 sqlstr 更改为此。 select * from viewReC_store where stk_date_time between CONVERT(DATETIME, '" + TextBox1.Text + "', 102) and CONVERT(DATETIME, '" + TextBox2.Text + "', 102)"

标签: c# sql-server


【解决方案1】:

好的,我知道了

           string sqlstr = "select * from viewReC_storeFG where stk_date_time between '" + TextBox1.Text + "' and '" + TextBox2.Text + "'";

感谢您的阅读和回复

关闭..

【讨论】:

    猜你喜欢
    • 2021-07-10
    • 1970-01-01
    • 2018-06-20
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    相关资源
    最近更新 更多