如何获取消息用户如果UserNo = @ UserNo和DatePrint不在同一天 [英] How to get message user exist IF UserNo=@UserNo and DatePrint not in same day

查看:120
本文介绍了如何获取消息用户如果UserNo = @ UserNo和DatePrint不在同一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题存在验证用户无法正常工作并给我错误的结果 

我不需要插入数据编码。

我的问题在这里我需要解决函数UserExistNotToday函数给我错误的结果

这样如何解决问题

我在Windows窗体中工作vs 2015 c#

I work in windows form vs 2015 c#

我在excel中有数据,我需要验证是否存在告诉我存在于excel表文件2007中。

I have data in excel and i need to validate if exist tell give me exist in excel sheet file 2007 .

我需要根据今天的日期验证存在的UserNo到excel文件

I need to validate exist UserNo to excel file based on date today

意味着他可以添加UserNo更多时间在同一天或今天,但

meaning he can add UserNo more time in same day or today but

如果他第二天进来,如果他之前找到,就不能再次插入UserNo。

if he come in next day cannot insert UserNo again if he found before .

我需要的例子

PrintDate 22/02/2017 UserNo 1016可以在同一天插入超过一个UserNo,这意味着我可以在22/02/2017多次使用UserNo 1016,但

PrintDate 22/02/2017 UserNo 1016 can insert more THAN one UserNo in same day meaning i can have UserNo 1016 more than one time in 22/02/2017 but

UserNo 1016第二天来自PrintDate 23/02/2017和UserNo已经f昨天在22/02/2017我不能在第二天再次添加

UserNo 1016 come next day as PrintDate 23/02/2017 and UserNo already found yesterday in date 22/02/2017 i cannot add again in next day

它会给我UserNo存在。

and it will give me UserNo Exist .

所以请帮助我

pesudo cod

pesudo cod

if(userno found in same day i add)

if (userno found in same day i add)

add user no

add user no

else

用户存在(如果我在2017年2月23日添加userno并且发现日期为22/02/2017)

user exist(if i add userno in 23/02/2017 and it found in date 22/02/2017)

我的代码

连接如下:

 string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:\\Attendance Sheet.xlsx;Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;");


public bool UserExistsNotToday(string UserNo,string DatePrint)
        {

            OleDbConnection cn = new OleDbConnection(connection);
            string str = "SELECT UserNo FROM  [Sheet1$] WHERE UserNo=UserNo AND DatePrint=@DatePrint";
            OleDbCommand cmd = new OleDbCommand(str, cn);

            
            cmd.Parameters.AddWithValue("@UserNo", UserNo);
            cmd.Parameters.AddWithValue("@DatePrint", DatePrint);
            cn.Open();
            var reader = cmd.ExecuteReader();
            return reader.HasRows;


        }






按钮下单击

我写

 QrClasses qrc = new QrClasses();
            bool b = qrc.UserExistsNotToday(textBox1.Text,textBox2.Text);
            if (b == true)
            {

              
                label3.Text = "User Exist";

            }
            else
            {
// here i will insert data
                label3.Text = "User Not Exist";


            }

表单加载我得到以下日期

in form load i get date as following

 DateTime thisDay = DateTime.Today;
            textBox2.Text = thisDay.ToString("dd/MM/yyyy");

和excel sheet i使用as以下:

and excel sheet i using as following :

推荐答案

你'重新使用datetime值,我怀疑你得到的值不对齐。当您在Excel中查看此数据时,您正在通过格式化程序查看它,因此它可能不是实际的基础值。我建议您将查询的
更改为仅搜索UserNo。然后枚举返回的每一行并将DatePrint列转换为DateTime(或至少验证格式)。然后,您可以使用
确定任何行是否具有该日期时间
任何
或其他LINQ命令。

You're working with datetime values and I suspect the values you are getting don't line up. When you're looking at this data in Excel you're looking at it through a formatter so it may not be the actual underlying value. I would recommend that you change your query to simply search for the UserNo. Then enumerate each row returned back and convert the DatePrint column to a DateTime (or at least verify the format). You can then determine if any row has that date time using Any or another LINQ command.

Michael Taylor

http://www.michaeltaylorp3。 net

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于如何获取消息用户如果UserNo = @ UserNo和DatePrint不在同一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆