using ShareA.DataBase;
using ShareA.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogicContract.ClinicInCharge
{
public class DoctordutyQuery
{
private string TableName = "Doctorduty"; //连接数据库Doctorduty
public List<DataContract.ClinicInCharge.DoctorDuty> Query(DateTime worktime) //查询操作
{
string sql = string.Empty, err;
sql = string.Format(@" select * from {0} where worktime={1} ", TableName, worktime);
DataTable dt = SqlHelper.QueryFromDatabase(ThisConn.sCono, sql, out err);
if (err.Length > 0)
{
throw new Exception(err);
}
return DataConverter.DataTableToIList<DataContract.ClinicInCharge.DoctorDuty>(dt).ToList();
}
}
}
27 个解决方案
#1
跟踪调试,把语句打印出来,只给代码,谁知道你调用的时候传的啥参数
#2
怎么跟踪调试,我是小白
#3
select * from '{0}' where worktime='{1}'
参数值外面加两个引号啊。。
#4
尴尬,表名不需要加引号,,后面的worktime加就可以了
#5
现在出现‘doctorduty’附近有语法错误
#6
看我后面一个回答,,,,表名那里不用加引号,
#7
sql = string.Format(@" select * from '{0}' where worktime='{1}' ", TableName, worktime);
我只改了这一句啊
#8
我知道了
#9
不是,,,就是这一句里面有两个参数,,,第一个参数也就是表名不用加引号。
select * from {0} where worktime='{1}'
#10
看我后面一个回答,,,,表名那里不用加引号,
sql = string.Format(@" select * from '{0}' where worktime='{1}' ", TableName, worktime);
我只改了这一句啊
不是,,,就是这一句里面有两个参数,,,第一个参数也就是表名不用加引号。
select * from {0} where worktime='{1}'
我按你的改出现从varchar数据类型到datetime数据类型的转换产生一个超出范围的值
#11
你的worktime加个ToString()试试?
worktime.ToString("yyyy-MM-dd HH:mm:ss");
#12
你的worktime加个ToString()试试?
worktime.ToString("yyyy-MM-dd HH:mm:ss");
还是一样的错误
#13
sql = string.Format(@"select * from {0} where worktime='{1:G}'", TableName, worktime);
得:select * from Doctorduty where worktime='2018-1-26 15:49:39'
#14
sql = string.Format(@"select * from {0} where worktime='{1:G}'", TableName, worktime);
得:select * from Doctorduty where worktime='2018-1-26 15:49:39'