C#字符串转datatime出错
static void Main(string[] args) { int j = sqlQueryTable("Data Source=ZHANGL;Initial Catalog=db_GVM;Integrated Security=True", "2012/11/4 12:41:16", "2012/11/4 12:41:56"); Console.WriteLine(j); Console.ReadKey(); } public static int sqlQueryTable(string specConnection, String startdatetime, String enddatetime) { int i = 0; try { using (SqlConnection conn = new SqlConnection(specConnection)) { string strCmd = "select count(*) from tb_PDU where datetime >= 'startdatetime' and datetime <= 'enddatetime' "; conn.Open(); SqlCommand sqlCmd = new SqlCommand(strCmd, conn); i = Convert.ToInt32(sqlCmd.ExecuteScalar()); conn.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message + ex.Source); } return i; }
string strCmd = "select count(*) from tb_PDU where datetime >= 'startdatetime' and datetime <= 'enddatetime' ";
C#里能这样解析吗?
string strCmd = "select count(*) from tb_PDU where datetime >= '"+startdatetime+"' and datetime <= '"+enddatetime+"' ";