关于在windows mobile5.0 上使用SQLite查询的问题?
DataManagement dm = new DataManagement(); bindingSource1.DataSource = dm.GetPatientOrder(patientId, "", conn); dataGrid1.DataSource = bindingSource1.DataSource; //============================================================== public DataTable GetPatientOrder(string patientId, string orderNo, SQLiteConnection conn) { string sqlSearch = ""; if (orderNo.Trim() != String.Empty) { sqlSearch += " AND Order_no=" + orderNo + " "; } string sql = @"SELECT *,case repeat_indicator when 1 then '长期' ELSE '临时' end repInd, '记录' as Performs FROM ORDERS where PATIENT_ID='" + patientId + "' " + sqlSearch + " "; SQLiteCommand cmd = new SQLiteCommand(sql, conn); SQLiteDataReader rdr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(rdr); rdr.Close(); return dt; }
#region 二分查找 /// <summary> /// 二分查找 /// </summary> /// <param name="CodeData">需查找的条码</param> /// <param name="InfoList">用于存放查询到的该条码的整条数据</param> /// <param name="RowLenght">控制每一行的总长度+2(回车算2个字符)</param> public void Bsearch(string CodeData, ArrayList InfoList,int RowLenght) { try { InfoList.Clear(); FileStream fs = new FileStream(@"MyAppData\data\down\lib.txt", FileMode.Open); long txtLenth = fs.Seek(0, SeekOrigin.End) / RowLenght; string tmp = ""; Byte[] rowData = new Byte[RowLenght]; long low = 0; long high = txtLenth - 1; long mid = 0; bool flag = false; long tmpMid = 0; Encoding chCode = Encoding.GetEncoding("GB2312"); while (low <= high) { mid = (low + high) / 2; fs.Seek(mid * RowLenght, SeekOrigin.Begin); fs.Read(rowData, 0, RowLenght); tmp = ""; tmp = chCode.GetString(rowData, 0, rowData.Length).Trim(); if (CodeData == tmp.Split((char)59)[0].Trim()) { InfoList.Add(tmp); flag = true; break; } else if (CodeData.CompareTo(tmp.Split((char)59)[0].Trim()) > 0) { low = mid + 1; } else { high = mid - 1; } } if (flag) { tmpMid = mid - 1; while (flag) { if (tmpMid < 0) { break; } fs.Seek(tmpMid * RowLenght, SeekOrigin.Begin); fs.Read(rowData, 0, RowLenght); tmp = ""; tmp = chCode.GetString(rowData, 0, rowData.Length).Trim(); if (CodeData == tmp.Split((char)59)[0].Trim()) { InfoList.Add(tmp); tmpMid--; } else { break; } } tmpMid = mid + 1; while (flag) { if (tmpMid > high) { break; } fs.Seek(tmpMid * RowLenght, SeekOrigin.Begin); fs.Read(rowData, 0, RowLenght); tmp = ""; tmp = chCode.GetString(rowData, 0, rowData.Length).Trim(); if (CodeData == tmp.Split((char)59)[0].Trim()) { InfoList.Add(tmp); tmpMid++; } else { break; } } fs.Close(); return; } else { fs.Close(); return; } } catch (IOException ex) { InfoList.Clear(); MessageBox.Show(ex.ToString()); return; } } #endregion
[解决办法]
学习!关注中!
[解决办法]
PDA最大的问题就是效率的问题,关注中.
看到Alan_pft文件二分查找方法,想到了R-tree查找方法.
帮顶.