DataTable.Select() PRoblem
-
I created a method that makes use of the .Select() method so that to check in a datatable if the value is already in the data table. For 1/4 of the recordss its working but at certain point it prompts out the fllowing error Min (14) must be less than or equal to max (-1) in a Range object. I am getting the data from MS Access. I have changed the databases so that to check if it was only with one version but It still showed me the error. only the number 14 changed. I have checked the records of the ids that the program was stopping all and they are all good values. Can some one help on that please. it is very urgent. THAnks alot for your time and help.
-
I created a method that makes use of the .Select() method so that to check in a datatable if the value is already in the data table. For 1/4 of the recordss its working but at certain point it prompts out the fllowing error Min (14) must be less than or equal to max (-1) in a Range object. I am getting the data from MS Access. I have changed the databases so that to check if it was only with one version but It still showed me the error. only the number 14 changed. I have checked the records of the ids that the program was stopping all and they are all good values. Can some one help on that please. it is very urgent. THAnks alot for your time and help.
jonhbt wrote:
it is very urgent
Of course it is, all questions here are urgent to the poster. But this is a free site so... (hint don't post that again) As to your problem can you provide the code that does the select (so your method) and some of the values where the code gives that error on?
-
jonhbt wrote:
it is very urgent
Of course it is, all questions here are urgent to the poster. But this is a free site so... (hint don't post that again) As to your problem can you provide the code that does the select (so your method) and some of the values where the code gives that error on?
Sry for that I didn't want to cause any problems the code that I am using is this
DataTable dtAllEmps = new DataTable(); dtAllEmps = cetData.GetALLEmployessByDate(conString, sensors); foreach (DataRow dataRow in dtAllEmps.Rows) { if(dtCSV.Rows.Count == 0) { DataRow newRow = dtCSV.NewRow(); newRow["UserID"] = dataRow["USERID"]; newRow["Department"] = dataRow["DEPTNAME"]; newRow["Date"] = dataRow["CHECKTIME"]; newRow["Name"] = dataRow["NAME"]; newRow["CheckType"] = dataRow["CHECKTYPE"]; dtCSV.Rows.Add(newRow); } else { Console.WriteLine("User ID " + dataRow["USERID"].ToString()); if (dataRow["USERID"].ToString() != "") { string strExpr = "UserID = " + dataRow["USERID"].ToString(); Console.WriteLine("Expression " + strExpr); DataRow[] filteredRows = dtCSV.Select(strExpr); if (filteredRows.Count() == 1) { Console.WriteLine("Number of Rows " + filteredRows.Count().ToString()); DataRow csvRow = filteredRows[0]; DateTime csvDate = Convert.ToDateTime(csvRow["Date"]); DateTime tableDate = Convert.ToDateTime(dataRow["CHECKTIME"]); Console.WriteLine("csvDate" + csvRow["Date"].ToString()); Console.WriteLine("tableDate" + dataRow["CHECKTIME"].ToString()); if (csvDate < tableDate) { filteredRows[0]["Date"] = tableDate.ToString(); filteredRows[0]["CheckType"] = dataRow["CHECKTYPE"].ToString(); filteredRows[0]["Department"] = dataRow["DEPTNAME"].ToString(); }
-
Sry for that I didn't want to cause any problems the code that I am using is this
DataTable dtAllEmps = new DataTable(); dtAllEmps = cetData.GetALLEmployessByDate(conString, sensors); foreach (DataRow dataRow in dtAllEmps.Rows) { if(dtCSV.Rows.Count == 0) { DataRow newRow = dtCSV.NewRow(); newRow["UserID"] = dataRow["USERID"]; newRow["Department"] = dataRow["DEPTNAME"]; newRow["Date"] = dataRow["CHECKTIME"]; newRow["Name"] = dataRow["NAME"]; newRow["CheckType"] = dataRow["CHECKTYPE"]; dtCSV.Rows.Add(newRow); } else { Console.WriteLine("User ID " + dataRow["USERID"].ToString()); if (dataRow["USERID"].ToString() != "") { string strExpr = "UserID = " + dataRow["USERID"].ToString(); Console.WriteLine("Expression " + strExpr); DataRow[] filteredRows = dtCSV.Select(strExpr); if (filteredRows.Count() == 1) { Console.WriteLine("Number of Rows " + filteredRows.Count().ToString()); DataRow csvRow = filteredRows[0]; DateTime csvDate = Convert.ToDateTime(csvRow["Date"]); DateTime tableDate = Convert.ToDateTime(dataRow["CHECKTIME"]); Console.WriteLine("csvDate" + csvRow["Date"].ToString()); Console.WriteLine("tableDate" + dataRow["CHECKTIME"].ToString()); if (csvDate < tableDate) { filteredRows[0]["Date"] = tableDate.ToString(); filteredRows[0]["CheckType"] = dataRow["CHECKTYPE"].ToString(); filteredRows[0]["Department"] = dataRow["DEPTNAME"].ToString(); }
I am writing the console calls so that to know what is the last value that the program is having. It is crashing in this part. The values when the program throws the exception differ.
string strExpr = "UserID = " + dataRow["USERID"].ToString(); Console.WriteLine("Expression " + strExpr); DataRow[] filteredRows = dtCSV.Select(strExpr);
-
Sry for that I didn't want to cause any problems the code that I am using is this
DataTable dtAllEmps = new DataTable(); dtAllEmps = cetData.GetALLEmployessByDate(conString, sensors); foreach (DataRow dataRow in dtAllEmps.Rows) { if(dtCSV.Rows.Count == 0) { DataRow newRow = dtCSV.NewRow(); newRow["UserID"] = dataRow["USERID"]; newRow["Department"] = dataRow["DEPTNAME"]; newRow["Date"] = dataRow["CHECKTIME"]; newRow["Name"] = dataRow["NAME"]; newRow["CheckType"] = dataRow["CHECKTYPE"]; dtCSV.Rows.Add(newRow); } else { Console.WriteLine("User ID " + dataRow["USERID"].ToString()); if (dataRow["USERID"].ToString() != "") { string strExpr = "UserID = " + dataRow["USERID"].ToString(); Console.WriteLine("Expression " + strExpr); DataRow[] filteredRows = dtCSV.Select(strExpr); if (filteredRows.Count() == 1) { Console.WriteLine("Number of Rows " + filteredRows.Count().ToString()); DataRow csvRow = filteredRows[0]; DateTime csvDate = Convert.ToDateTime(csvRow["Date"]); DateTime tableDate = Convert.ToDateTime(dataRow["CHECKTIME"]); Console.WriteLine("csvDate" + csvRow["Date"].ToString()); Console.WriteLine("tableDate" + dataRow["CHECKTIME"].ToString()); if (csvDate < tableDate) { filteredRows[0]["Date"] = tableDate.ToString(); filteredRows[0]["CheckType"] = dataRow["CHECKTYPE"].ToString(); filteredRows[0]["Department"] = dataRow["DEPTNAME"].ToString(); }
Can you put a Try Catch in there and post the error message from the catch? Put the whole block of code from the foreach in a try block and then a catch at the end. This should give you better idea of what the error is.
Excellence is doing ordinary things extraordinarily well.
-
I am writing the console calls so that to know what is the last value that the program is having. It is crashing in this part. The values when the program throws the exception differ.
string strExpr = "UserID = " + dataRow["USERID"].ToString(); Console.WriteLine("Expression " + strExpr); DataRow[] filteredRows = dtCSV.Select(strExpr);
Don't worry you didn't cause problems, was just a hint. Another hint: When posting code use the 'code block' tags, makes it easier to read the code. As to your problem. At what userid does the error occur? My guess would be that since you do a 'tostring' your userid is of the type string (varchar). If so your filter expression should be:
"UserID = '" + datarow["USERID"].ToString() + "'";
-
Can you put a Try Catch in there and post the error message from the catch? Put the whole block of code from the foreach in a try block and then a catch at the end. This should give you better idea of what the error is.
Excellence is doing ordinary things extraordinarily well.
-
Don't worry you didn't cause problems, was just a hint. Another hint: When posting code use the 'code block' tags, makes it easier to read the code. As to your problem. At what userid does the error occur? My guess would be that since you do a 'tostring' your userid is of the type string (varchar). If so your filter expression should be:
"UserID = '" + datarow["USERID"].ToString() + "'";
thanks for the advices. Regarding to the problem the values are Numbers in the database. There wasn't only one value since i tried different values. One of them was 279 which was giving problems. the strange thing is that this process runs for most of the values but at a certain point in time it stops. that is why i am confused, since all the values that are being passed are numbers.
-
thanks for the advices. Regarding to the problem the values are Numbers in the database. There wasn't only one value since i tried different values. One of them was 279 which was giving problems. the strange thing is that this process runs for most of the values but at a certain point in time it stops. that is why i am confused, since all the values that are being passed are numbers.
Is your userid column in the datatable numeric? If so remove the tostring (not needed here) If not try the code I gave (but I don't think that's the problem)
jonhbt wrote:
the strange thing is that this process runs for most of the values but at a certain point in time it stops
Does it always stop at the same value? or is random? Are you using multi - threading?
-
Is your userid column in the datatable numeric? If so remove the tostring (not needed here) If not try the code I gave (but I don't think that's the problem)
jonhbt wrote:
the strange thing is that this process runs for most of the values but at a certain point in time it stops
Does it always stop at the same value? or is random? Are you using multi - threading?
-
no im not useing multi threading. The value is the same only for the set of values chosen. WHen i change the set of values by a filter from the select command in the database, the value is different.
When you debug and stop at the select line try doing a 'quick watch' (right mouse click) Then run the select (dtscv.select("Userid=" + newrow["userid"]) ). Does that work? Is the value present or not? Can you post your declaration of the dtscv datatable? (specifically the column declarations )
-
When you debug and stop at the select line try doing a 'quick watch' (right mouse click) Then run the select (dtscv.select("Userid=" + newrow["userid"]) ). Does that work? Is the value present or not? Can you post your declaration of the dtscv datatable? (specifically the column declarations )
This is my declaration of te DataTable
DataColumn Column1 = new DataColumn("Name");
DataColumn Column2 = new DataColumn("Department");
DataColumn Column3 = new DataColumn("Date");
DataColumn Column4 = new DataColumn("UserID");
DataColumn Column5 = new DataColumn("CheckType");dtCSV.Columns.Add(Column1); dtCSV.Columns.Add(Column2); dtCSV.Columns.Add(Column3); dtCSV.Columns.Add(Column4); dtCSV.Columns.Add(Column5);
Ill try what you suggested
-
This is my declaration of te DataTable
DataColumn Column1 = new DataColumn("Name");
DataColumn Column2 = new DataColumn("Department");
DataColumn Column3 = new DataColumn("Date");
DataColumn Column4 = new DataColumn("UserID");
DataColumn Column5 = new DataColumn("CheckType");dtCSV.Columns.Add(Column1); dtCSV.Columns.Add(Column2); dtCSV.Columns.Add(Column3); dtCSV.Columns.Add(Column4); dtCSV.Columns.Add(Column5);
Ill try what you suggested
try:
DataColumn Column4 = new DataColumn("UserID",typeof(int));
-
try:
DataColumn Column4 = new DataColumn("UserID",typeof(int));