| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2607 人关注过本帖
标题:[求助]我做的登陆界面代码出错??
只看楼主 加入收藏
ugene
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:6 
[求助]我做的登陆界面代码出错??

最近我再用vs2003做学生管理系统,登陆界面已经做好,在调试的时候也没出现什么错误,可是我输入用户名和密码后没什么反映,当我关闭后又说我有错误
“DefaultDomain”: 已加载“c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll”,未加载符号。
“StudentManage”: 已加载“c:\winnt\assembly\gac\mscorlib.resources\1.0.5000.0_zh-chs_b77a5c561934e089\mscorlib.resources.dll”,未加载符号。
“StudentManage”: 已加载“D:\hsc\StudentManage\StudentManage\bin\Debug\StudentManage.exe”,符号已加载。
“StudentManage.exe”: 已加载“c:\winnt\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll”,未加载符号。
“StudentManage.exe”: 已加载“c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll”,未加载符号。
“StudentManage.exe”: 已加载“c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll”,未加载符号。
程序“[1760] StudentManage.exe”已退出,返回值为 0 (0x0)。
程序代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace StudentManage
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox textUserID;
private System.Windows.Forms.TextBox textUserPassword;
private System.Windows.Forms.Button btnApply;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textUserID = new System.Windows.Forms.TextBox();
this.textUserPassword = new System.Windows.Forms.TextBox();
this.btnApply = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(448, 104);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// textUserID
//
this.textUserID.Location = new System.Drawing.Point(232, 136);
this.textUserID.Name = "textUserID";
this.textUserID.Size = new System.Drawing.Size(112, 21);
this.textUserID.TabIndex = 0;
this.textUserID.Text = "";
//
// textUserPassword
//
this.textUserPassword.Location = new System.Drawing.Point(232, 192);
this.textUserPassword.Name = "textUserPassword";
this.textUserPassword.PasswordChar = '*';
this.textUserPassword.Size = new System.Drawing.Size(112, 21);
this.textUserPassword.TabIndex = 2;
this.textUserPassword.Text = "";
//
// btnApply
//
this.btnApply.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.btnApply.Font = new System.Drawing.Font("华文行楷", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnApply.ForeColor = System.Drawing.Color.White;
this.btnApply.Location = new System.Drawing.Point(112, 264);
this.btnApply.Name = "btnApply";
this.btnApply.Size = new System.Drawing.Size(72, 32);
this.btnApply.TabIndex = 3;
this.btnApply.Text = "确 定";
this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
//
// btnCancel
//
this.btnCancel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.btnCancel.Font = new System.Drawing.Font("华文行楷", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnCancel.ForeColor = System.Drawing.Color.White;
this.btnCancel.Location = new System.Drawing.Point(264, 264);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(80, 32);
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "重 填";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(144, 136);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 24);
this.label1.TabIndex = 2;
this.label1.Text = "用户名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(144, 192);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 24);
this.label2.TabIndex = 3;
this.label2.Text = "密 码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// pictureBox2
//
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(48, 160);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(48, 48);
this.pictureBox2.TabIndex = 63;
this.pictureBox2.TabStop = false;
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 357);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnApply);
this.Controls.Add(this.textUserPassword);
this.Controls.Add(this.textUserID);
this.Controls.Add(this.pictureBox1);
this.Name = "Login";
this.Text = "登录系统";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Login());
}

private void btnCancel_Click(object sender, System.EventArgs e)
{
this.textUserID.Text="";
this.textUserPassword.Text="";
}

private void btnApply_Click(object sender, System.EventArgs e)
{
string userid=textUserID.Text.Trim();
string userpassword=textUserPassword.Text.Trim();
if(userid!=""&&userpassword!="")//用户名和密码不能为空
{
//try
// {
SqlConnection conn=new SqlConnection();//建立数据库链接
conn.ConnectionString="server=(local);Integrated Security=SSPI;database=StudentManage;Connection Timeout=5";
try
{
conn.Open();
string strcmd="select * from User";//从User表中取数据
SqlDataAdapter da=new SqlDataAdapter(strcmd,conn);
DataSet ds=new DataSet();//拷贝到内存,得到空的DataSet
da.Fill(ds,"User");//用Fill()函数填充
DataTable dt=ds.Tables["User"];



foreach(DataRow row in dt.Rows)
{
if(row["UserID"].ToString().Trim()==userid&&row["UserPassword"].ToString().Trim()==userpassword)
{
Form MainForm=new Form();
MainForm.ShowDialog();
}
else
{
if(MessageBox.Show("输入的用户名或密码有误,是否重新登录?","输入有误",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
this.textUserID.Clear();
this.textUserPassword.Clear();
}//输入有误,重新输入。
}
}
}
catch(Exception ex)
{
Console.WriteLine("Error:"+ex.Message);
conn.Close();

}

// }
//catch(Exception ex)
//{
// Console.WriteLine("Error:"+ex.Message);
// conn.Close();
//}//捕获异常
// finally
// {
// conn.Close();
//}
}

}

}
}

搜索更多相关主题的帖子: 界面 代码 登陆 
2007-05-29 17:00
欢天喜地
Rank: 2
等 级:论坛游民
威 望:2
帖 子:83
专家分:20
注 册:2007-5-13
收藏
得分:0 
你的写法我不太常用,可以这样写会好点

if(用户名==ds.rows[那行][那列].toString() && 密码==ds.rows[那行][那列].toString())
{
MessageBox("登陆成功");
}
else
{
MessageBox("登陆失败");
}

当然如果数据库中有多条数据就必须在if外面加个循环进行判断
因为行是不固定的,但是列我们是可以确定的;这样做可能出错的机会少一点!
2007-06-09 22:11
codeboy
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-3-20
收藏
得分:0 

在foreach语句里能用if else 判断么?我以前用的好像不行哦。条件满足时还可以。
但不满足时代码是不会被执行的。


编程 != 码字
2007-06-11 16:15
Princeli1125
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-6-11
收藏
得分:0 
学习学习

新手接触C#,大家多关照!
2007-06-11 20:45
xiangjian223
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2007-5-21
收藏
得分:0 
我都是用的datareader 来判断的。。。用sdr.Hasrows().呵呵 意思是名和密码都对的记录如果存在,不为空就登录.
2007-06-11 23:45
大连乖乖猫
Rank: 1
等 级:新手上路
威 望:1
帖 子:32
专家分:0
注 册:2007-4-25
收藏
得分:0 
添加mscorlib.dll引用

2007-06-12 08:48
卡卡艾
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:672
专家分:0
注 册:2007-4-3
收藏
得分:0 

我也来贴一个,LZ或许可以试一下:
private void btn_ok_Click(object sender, System.EventArgs e)
{
string user,password;

user=this.textBox1.Text.ToString().Trim();
password=this.textBox2.Text.ToString().Trim();


if(user=="")
{
MessageBox.Show( "用户名不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if(password=="")
{
MessageBox.Show( "密码不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}

string mysource="Data Source=服务器名;Initial Catalog=数据库;Integrated Security=SSPI";
SqlConnection conn=new SqlConnection(mysource);
try
{
conn.Open();
}
catch
{
MessageBox.Show("连接数据库失败","提示",MessageBoxButtons.OK ,MessageBoxIcon.Stop );
this.Cursor = Cursors.Default ;
return;
}

SqlCommand cmd = conn.CreateCommand();
cmd.CommandText="Select * from TABLE1 where username='"+user+"'";

SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr["password"].ToString().Trim() ==password )
{
MessageBox.Show("系统登陆成功!");
Form fm2=new Form2();
fm2.Show();

}
else
{
MessageBox.Show("您输入的用户信息或密码不正确!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("没有此用户");
}
dr.Close();
conn.Close();
return;

}


革命尚未成功,同志仍需努力-----+++
2007-06-12 22:37
快速回复:[求助]我做的登陆界面代码出错??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056134 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved