ADO处起步

空间昨天就开通了,因为自己懒,所以知道今天才写日志,没什么好说的,为了怕自己继续懒下去,因此要求自己每天把学习成果记下来,以此督促自己每天学习,无意瞥见的编程大大们又闲来无事的,还望留下自己的qq号,或者空间号也行,实在没有时间的,在文章下面随便点拨几句也能使我如获至宝。

今天还是啃老本的学习,ADO以前学过,怕自己忘掉,所以又回头看看视频,所谓学而实习,温故知新。 代码也没写多少,多是一些基础的代码,其实高深的东西也不怎么会,今天复习的是一个用户登录验证的小短,代码如下:

 class Program

    {

        static void Main(string[] args)

        {

           string dataDir = AppDomain.CurrentDomain.BaseDirectory;

            if (dataDir.EndsWith(@"/bin/Debug/") || dataDir.EndsWith(@"/bin/Release/"))

            {

                dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;

                AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);

            }

            Console.WriteLine("input name");

            string name=Console.ReadLine();

            Console.WriteLine("input possword");

            string passwords=Console.ReadLine();

            using (SqlConnection conn = new SqlConnection("Data Source=EAVE;Initial Catalog=firstdata;Integrated Security=True"))

            {

                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())

                {

                    cmd.CommandText = "select * from lianxi where name='" + name + "'";

                    using (SqlDataReader reader = cmd.ExecuteReader())

                    {

                        if (reader.Read())

                        {

                            reader.Close();

                           cmd.CommandText = "select * from lianxi where id='" + passwords + "'";

                           using (SqlDataReader readers = cmd.ExecuteReader())

                           {

                               if (readers.Read())

                               {

                                   Console.WriteLine("登陆成功!");

                               }

                               else

                               {

                                   Console.WriteLine("密码错误");

                               }

                           }

                        }

                        else

                        {

                            Console.WriteLine("用户名错误!");

 

                        }

                    }

                }

                conn.Close();

                Console.ReadLine();

            }

        }

这是个控制台的程序,为了迎合表的方便,把表中的ID作密码使了,程序是没什么错误的,但是有一个困扰了我一天的问题就是密码不验证,我已经找了也就是说,无论密码错与对,只要正确输入了用户名,便可成功登录,这让我很是烦闷,调试了好久,终未果,望各位大大碰见指点一二。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值