空间昨天就开通了,因为自己懒,所以知道今天才写日志,没什么好说的,为了怕自己继续懒下去,因此要求自己每天把学习成果记下来,以此督促自己每天学习,无意瞥见的编程大大们又闲来无事的,还望留下自己的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作密码使了,程序是没什么错误的,但是有一个困扰了我一天的问题就是密码不验证,我已经找了也就是说,无论密码错与对,只要正确输入了用户名,便可成功登录,这让我很是烦闷,调试了好久,终未果,望各位大大碰见指点一二。