如何在C#中的sql命令中传递两个变量?

use*_*595 0 c# sql ssis

真的是一个简单的问题,我有两个变量"one_hour_ago"和"current_time",我需要在我的sql命令中传递这两个变量,如:

string commandString = "SELECT * from myTable where time between one_hour_ago and current_time";
Run Code Online (Sandbox Code Playgroud)

这是我的,但我得到语法错误

string commandString = "SELECT * from myTable where TS between ' and /" + one_hour_ago + "'" + current_time + "/"; 
Run Code Online (Sandbox Code Playgroud)

谢谢

Tho*_*and 7

string sqlString = "SELECT * FROM myTable WHERE time BETWEEN  @before AND @current_time"; 
SqlCommand oCmd = new SqlCommand(sqlString , connString);
oCmd.Parameters.AddWithValue("@before", date_before);
oCmd.Parameters.AddWithValue("@current_time", currentTime);
Run Code Online (Sandbox Code Playgroud)

where date_beforecurrentTime是传递给方法的参数.

这应该照顾sql注入的东西