I’m working on an old .NET 2.0 site that’s having an issue with date searches.
After a few hours of troubleshooting I’ve come to the conclusion that the search parameters being sent are in a MM/DD/YYYY format and SQL Server is expecting DD/MM/YYYY
I’m not sure how to fix this.
I’ve tried converting it to string with ( .ToString("dd/MM/yyyy") ) then back to DateTime. This isn’t working because it needs to be a nullable DateTime
CS1502: The best overloaded method match for ‘TableAdapters.Artist_ListTableAdapter.GetData(int, System.DateTime?,
System.DateTime?, int?, int?, bool?, string, string, string, int?,
int?, int?, int?, int?, out int?)’ has some invalid arguments
Now I don’t understand much about SQL Server stored procedures so I have no idea how to look at that GetData function… when I right click and go to definition I get a generated c# page.
Any help?
EDIT: @BigM Not sure if this will help but:
Var declaration:
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;
Grabbed from query string:
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();
}
Then later on in the code:
dtArtist = objArtistLayer.getArtistList(CultureId,startDate, endDate, disciplineId, languageId, minimumGradelevel, maximumGradelevel, isFeatured, sortColumnName, searchCriteria, EducationalInitiativeIds, Stakeholder, currPage, pageSize, out rowCount);
Then later on:
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;
DateTimedoesn’t have a format – it’s just a date/time value. Converting it to a string then converting it back to a date is useless – you’re going to get the same value back.Your issue is more likely when you’re converting the
QueryStringparameters from strings to dates. This is the only place in the code you’ve posted that represents dates as strings. You need to have some way to enforce a particular format, otherwiseConvert.ToDateTimegoing to try and infer the format, which could be wrong when the month and day are ambiguous. e.g. is 2/3/2013 Feb 3rd or Mar 2nd?If your query string variable is ALWAYS in the format
mm/dd/yyyythen useParseExactto convert it to aDateTime: