最近我再用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();
//}
}
}
}
}