我在一个旧的 .NET 2.0 网站上工作,该网站在日期搜索方面存在问题。
经过几个小时的故障排除后,我得出的结论是,正在发送的搜索参数是一种MM/DD/YYYY
格式,并且 SQL Server 正在等待DD/MM/YYYY
我不知道如何解决这个问题。
我尝试使用 ( .ToString("dd/MM/yyyy")
) 将其转换为字符串,然后再转换为DateTime
. 这不起作用,因为它必须是可空的DateTime
CS1502:最佳重载方法匹配 'TableAdapters.Artist_ListTableAdapter.GetData(int, System.DateTime?, System.DateTime?, int?, int?, bool?, string, string, string, int?, int?, int? , int?, int?, out int?)' 有一些无效参数
现在我对 SQL Server 存储过程不太了解,所以我不知道如何查看该GetData
函数......当我右键单击并转到定义时,我得到一个生成的 c# 页面。
有什么帮助吗?
编辑:@BigM 不确定这是否会有所帮助,但是:
变量声明:
public DataTable dtArtist = new DataTable();
public string cp_basePath;
public int pagecount;
int CultureId ;
DateTime? startDate;
DateTime? endDate;
int? disciplineId = null;
int? minimumGradelevel = null;
int? maximumGradelevel = null;
int? languageId = null;
bool? isFeatured = null;
int? educationalInitiativeId = null;
string EducationalInitiativeIds = string.Empty;
string sortColumnName = string.Empty;
string searchCriteria = string.Empty;
从查询字符串中获取:
private void GetQueryStrings()
{
CultureId = objGeneralLayer.plCultureId;
if (Request.QueryString["StartDate"] != null)
startDate = Convert.ToDateTime(Request.QueryString["StartDate"].ToString(), CultureInfo.InvariantCulture);
if (Request.QueryString["EndDate"] != null)
endDate = Convert.ToDateTime(Request.QueryString["EndDate"].ToString(), CultureInfo.InvariantCulture);
if (Request.QueryString["DisciplineId"] != null)
disciplineId = Convert.ToInt32(Request.QueryString["DisciplineId"].ToString());
if (Request.QueryString["MinGrade"] != null)
minimumGradelevel = Convert.ToInt32(Request.QueryString["MinGrade"].ToString());
if (Request.QueryString["MaxGrade"] != null)
maximumGradelevel = Convert.ToInt32(Request.QueryString["MaxGrade"].ToString());
if (Request.QueryString["LanguageId"] != null)
languageId = Convert.ToInt32(Request.QueryString["LanguageId"].ToString());
if (Request.QueryString["Featured"] != null)
isFeatured = Convert.ToBoolean(Request.QueryString["Featured"].ToString());
if (Request.QueryString["EducatIds"] != null)
EducationalInitiativeIds = Request.QueryString["EducatIds"].ToString();
if (Request.QueryString["Criteria"] != null)
searchCriteria = Request.QueryString["Criteria"].ToString();
}
然后在代码中:
dtArtist = objArtistLayer.getArtistList(CultureId,startDate, endDate, disciplineId, languageId, minimumGradelevel, maximumGradelevel, isFeatured, sortColumnName, searchCriteria, EducationalInitiativeIds, Stakeholder, currPage, pageSize, out rowCount);
然后稍后:
public DataTable getArtistList( int CultureId ,
DateTime? StartDate
,DateTime? EndDate
,int? DisciplineId
,int? LanguageId
,int? MinimumGradeLevel
,int? MaximumGradeLevel
,bool? IsFeature
,string ColumnName
,string Criteria
,string EducationalInitiativeIds
,int ? StakeholderId
,int StartPage
,int PageSize
,out int RowCount
)
{
int? count = 0;
StartDate = Convert.ToDateTime(StartDate);
DataTable dt = new DataTable();
TableAdapters.Artist_ListTableAdapter ada = new TableAdapters.Artist_ListTableAdapter();
dt = ada.GetData(CultureId
, StartDate
, EndDate
, MinimumGradeLevel
, MaximumGradeLevel
, IsFeature
, ColumnName
, Criteria
, EducationalInitiativeIds
, StakeholderId
, DisciplineId
, LanguageId
, StartPage
, PageSize
, out count
);
RowCount = (int)count;
return dt;