现在的问题是这样 
1,我在SQL Server查询分析器中运行 如:
select datediff(month, '2008-01-01', getdate())
可以返回查询结果3
2,现在想在C#代码中实现类似的功能 为什么没有返回结果?
数据库中有一个字段为"MileStone_Time" (Datetime类型)
先创建数据库连接,dataset ... 经测试没有问题string DateinMileStone = ds.Tables["MileStone"].DefaultView.Table.Rows[0]["MileStone_Time"].ToString(); // 经测试 正确返回时间字段
string DateNow = System.DateTime.Now.ToString();
string SQL_CountMonths = "SELECT DATEDIFF(month, '"+DateinMileStone+"', '"+DateNow+"')"
SqlCommand countMonths = new SqlCommand(SQL_CountMonths, connectstr); // connectstr已声明
int count_Months = Convert.ToInt32(countMonths.ExecuteScalar().ToString());为什么count_Months没有返回结果?