小编Car*_*los的帖子

SQL GetDate()返回错误的时间

我在使用时遇到问题GetDate(),由于某种原因没有返回正确的时间(比实际时间提前7小时)我正在使用AZURE并且数据库配置了正确的位置(美国西部).我将不胜感激任何帮助!

我试着运行这个脚本:

SELECT id,
       status,
       AcceptedDate,
       Getdate(),
       Datediff(hour, AcceptedDate, Getdate())
FROM   orderoffers
WHERE  status = 'Accepted' 
Run Code Online (Sandbox Code Playgroud)

sql getdate azure-sql-database

3
推荐指数
1
解决办法
5485
查看次数

使用带参数的存储过程修改 SqlDataSource.SelectCommand

我正在尝试在我的应用程序中创建一个搜索框,为此我需要修改 SqlDataSource.SelectCommand。我将不胜感激任何帮助!

为了进行测试,我这样做了,它可以工作,但很容易受到 sql 注入的攻击

   SqlDataSource1.SelectCommand = "sp_offer_search '" + txtSearch.Text + "', " +   Session["customerId"] + " , '" + "Pending"+ "'";
   GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止所尝试的,但它不起作用:

 if (txtSearch.Text != "")
        {                
         //open connection
          oCn.Open();
          SqlCommand com = new SqlCommand(query, oCn);
          com.CommandType = CommandType.StoredProcedure;

          com.Parameters.AddWithValue("@Variable", txtSearch.Text);  
          com.Parameters.AddWithValue("@CustomerId",Session["customerId"]);   
          com.Parameters.AddWithValue("@Status", txtStatus.Text);   


            DataTable dt = new DataTable();
            dt.Load(com.ExecuteReader());

            SqlDataSource1.SelectCommand = dt.ToString();
            GridView1.DataBind();
       }
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server sqldatasource

2
推荐指数
1
解决办法
848
查看次数