OracleDataReader.Read()是否有值

当你执行一次OracleDataReader.Read()事件后,OracleDataReader只读取一条以前从未记录过的纪录,并返回值 True(OracleDataReader.Read()是Bool型),注意是只读取一个!如果你的Select语句执行结果是空,或者所有的结果都已经读取完了则OracleDataReader()返回False。所以想实现判断记录是否为空时刻可以用下面方法:
OracleConnection   dbcnt;//定义一个数据库连接
OracleDataCommand   dbcmd;//定义一个数据库命令行
OracleDataReader   dbreader;//定义一个DataReader
dbcnt.ConnectionString= "你的连接字符串 ";
dbcmd.Connection=dbcnt;
dbcmd.CommandText= "select   a   from   b   where   a=c ";//SQL查询语句
dbcmd.Connection.Open();//连接到数据库
dbreader=dbcmd.ExecutReader();//用上面的SQL查询语句构造DataReader
if(dbreader.Read())//如果SQL查询有结果,并且没有读完则执行{...}的内容。否则跳过。
  {
      ......
  }
dbcmd.Connection.Close();//关闭数据库连接
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace DefectByDieAlarmToPPT_Weekly { public class PublicValues { private static string todayStr = string.Empty; private static string projectMainPath = string.Empty; private static string weeklyYLAlarmInfoPath = string.Empty; private static string weeklyYPLAlarmInfoPath = string.Empty; private static string htmlStrSavaPath = string.Empty; private static Dictionary<string, List<string>> savePathDic; private static Tuple<int, int> chartWidHith; private static List<string> weeklyList; private static string runWeek; private static int weekScore = 0; private static double weekScoreRecipeMatch = 0; private static Tuple<int, int> headTailFontSize; private static Tuple<int, int> fontBgColor; public static Tuple<int, int> FontBgColor { get { return PublicValues.fontBgColor; } set { PublicValues.fontBgColor = value; } } public static Tuple<int, int> HeadTailFontSize { get { return PublicValues.headTailFontSize; } set { PublicValues.headTailFontSize = value; } } public static int WeekScore { get { return PublicValues.weekScore; } set { PublicValues.weekScore = value; } } public static double WeekScoreRecipeMatch { get { return PublicValues.weekScoreRecipeMatch; } set { PublicValues.weekScoreRecipeMatch = value; } } private static int alarmCount = 0; public static int AlarmCount { get { return PublicValues.alarmCount; } set { PublicValues.alarmCount = value; } } public static string RunWeek { get { return PublicValues.runWeek; } set { PublicValues.runWeek = value; } } public static List<string> WeeklyList { get { return PublicValues.weeklyList; } } public static string ProjectMainPath { get { return projectMainPath; } set { projectMainPath = value; } } public static string WeeklyYLAlarmInfoPath { get { return weeklyYLAlarmInfoPath; } set { weeklyYLAlarmInfoPath = value; } } public static string WeeklyYPLAlarmInfoPath { get { return weeklyYPLAlarmInfoPath; } set { weeklyYPLAlarmInfoPath = value; } } public static string HtmlStrSavaPath { get { return PublicValues.htmlStrSavaPath; } set { PublicValues.htmlStrSavaPath = value; } } public static string TodayStr { get { return PublicValues.todayStr; } set { PublicValues.todayStr = value; } } public static void intalaziDic() { savePathDic = new Dictionary<string, List<string>>(); GetWeeklyList(); } public static Dictionary<string, List<string>> SavePathDic { get { return PublicValues.savePathDic; } set { PublicValues.savePathDic = value; } } public static void SavePathDicAdd(string category, string path) { if (!PublicValues.savePathDic.ContainsKey(category)) { PublicValues.savePathDic.Add(category, new List<string>()); } PublicValues.savePathDic[category].Add(path); } public static void SavePathDicClear() { PublicValues.savePathDic.Clear(); } public static Tuple<int, int> ChartWidHith { get { return PublicValues.chartWidHith; } set { PublicValues.chartWidHith = value; } } private static void GetWeeklyList() { DateTime runTime = PublicFunction.StrToDateTime(PublicValues.TodayStr); PublicValues.weeklyList = new List<string>(); for (int i = 1; i <= 7; i++) { string weekly = GetWeekOfYear(runTime.AddDays(-(7 * i))); if (PublicValues.weeklyList.Contains(weekly)) { PublicValues.weeklyList.Add("2021W52"); } else { PublicValues.weeklyList.Add(weekly); } //PublicValues.weeklyList.Add } // PublicValues.weeklyList.Reverse PublicValues.weeklyList.Sort(); //; //DBConnector conn = new DBConnector(ConnectStr.YmsDBString); //string getWeeklySql = "SELECT DISTINCT DATATIME FROM ESPT_DEFECT_YL_WEEK ORDER BY DATATIME"; //System.Data.OracleClient.OracleDataReader reader = conn.DBRead(getWeeklySql); //while (reader.Read()) //{ // PublicValues.weeklyList.Add(reader.GetString(0)); //} //if (PublicValues.weeklyList.Count != 7) //{ // Console.WriteLine("Get Weekly Info Error;\nPlease Check ymdDB.Table:ESPT_DEFECT_YL_WEEK DataTime Info."); // conn.DBClose(); // Console.ReadKey(); // Environment.Exit(0); //} //conn.DBClose(); } public static string GetWeekOfYear(DateTime datetime) { //int mondayDiff = Convert.ToInt32(datetime.DayOfWeek); int firstDayOfYearInWeek = Convert.ToInt32(PublicFunction.StrToDateTime(datetime.Year + "-01-01").DayOfWeek); if (firstDayOfYearInWeek == 0) { firstDayOfYearInWeek = 7; } int dayOfYear = datetime.DayOfYear; int dayDiff = 0; if (firstDayOfYearInWeek >= 5) { dayDiff = -(7 - firstDayOfYearInWeek + 1); } else if (firstDayOfYearInWeek >= 1) { dayDiff = firstDayOfYearInWeek - 1; } double weekly = Math.Ceiling((dayOfYear + dayDiff) / 7d); int todayInWeek = Convert.ToInt32(datetime.DayOfWeek); if (todayInWeek == 0) { todayInWeek = 7; } DateTime firstDayOfTheWeek = datetime.AddDays(-todayInWeek); DateTime lastDayOfTheWeek = firstDayOfTheWeek.AddDays(6); int year = datetime.Year; if (firstDayOfTheWeek.Year < lastDayOfTheWeek.Year) { if (Convert.ToInt32(datetime.DayOfWeek) <= 3) { year = datetime.AddYears(1).Year; weekly = 1; } } if (weekly == 0) { weekly++; } string resultWeekly = weekly.ToString().PadLeft(2, '0'); return year + "W" + resultWeekly; } } } 上述代码定义了todayStr吗
最新发布
11-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值