首页上一页 1 下一页尾页 1 条记录 1/1页
c#企业人事管理系统登录界面报出NullReferenceExcepiton
发表在C#图书答疑
2010-07-28
是否精华
是
否
版块置顶:
是
否
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PWMS
{
public partial class F_Login : Form
{
DataClass.MyMeans MyClass = new PWMS.DataClass.MyMeans();
public F_Login()
{
InitializeComponent();
}
private void textName_TextChanged(object sender, EventArgs e)
{
}
private void textName_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
textPass.Focus();
}
private void textPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
butLogin.Focus();
}
private void butClose_Click(object sender, EventArgs e)
{
if ((int)(this.Tag) == 1)
{
DataClass.MyMeans.Login_n = 3;
Application.Exit();
}
else
if ((int)(this.Tag) == 2)
this.Close();
}
private void butLogin_Click(object sender, EventArgs e)
{
if (textName.Text != "" & textPass.Text != "")
//用自定义方法getcom()在tb_Login数据库表中查找是否有当前登录用户
{
SqlDataReader temDR = MyClass.getcom("select * from tb_Login where Name='" + textName.Text.Trim() + "'and Pass='" + textPass.Text.Trim() + "'");
bool ifcom = temDR.Read();
if (ifcom)
{
DataClass.MyMeans.Login_Name = textName.Text.Trim(); //将当前用户名记录到全局变量中去
DataClass.MyMeans.Login_ID = temDR.GetString(0);
DataClass.MyMeans.My_con.Close(); //关闭连接
DataClass.MyMeans.My_con.Dispose(); //释放资源
[font color=#FF0000] DataClass.MyMeans.Login_n = (int)(this.Tag); [/font]
this.Close();
}
else
{
MessageBox.Show("用户名不存在或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textName.Text = "";
textPass.Text = "";
}
MyClass.con_close();
}
else
{
MessageBox.Show("用户名和密码不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void F_Login_Load(object sender, EventArgs e)
{
try
{
MyClass.con_open(); //连接数据库
MyClass.con_close();
textName.Text = "";
textPass.Text = "";
}
catch
{
MessageBox.Show("数据库连接失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}
}
版主你好,在我程序中的这句
DataClass.MyMeans.Login_n = (int)(this.Tag);
报出了NullReferenceException
注:这段代码是我模仿你们的源程序写的
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PWMS
{
public partial class F_Login : Form
{
DataClass.MyMeans MyClass = new PWMS.DataClass.MyMeans();
public F_Login()
{
InitializeComponent();
}
private void textName_TextChanged(object sender, EventArgs e)
{
}
private void textName_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
textPass.Focus();
}
private void textPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
butLogin.Focus();
}
private void butClose_Click(object sender, EventArgs e)
{
if ((int)(this.Tag) == 1)
{
DataClass.MyMeans.Login_n = 3;
Application.Exit();
}
else
if ((int)(this.Tag) == 2)
this.Close();
}
private void butLogin_Click(object sender, EventArgs e)
{
if (textName.Text != "" & textPass.Text != "")
//用自定义方法getcom()在tb_Login数据库表中查找是否有当前登录用户
{
SqlDataReader temDR = MyClass.getcom("select * from tb_Login where Name='" + textName.Text.Trim() + "'and Pass='" + textPass.Text.Trim() + "'");
bool ifcom = temDR.Read();
if (ifcom)
{
DataClass.MyMeans.Login_Name = textName.Text.Trim(); //将当前用户名记录到全局变量中去
DataClass.MyMeans.Login_ID = temDR.GetString(0);
DataClass.MyMeans.My_con.Close(); //关闭连接
DataClass.MyMeans.My_con.Dispose(); //释放资源
[font color=#FF0000] DataClass.MyMeans.Login_n = (int)(this.Tag); [/font]
this.Close();
}
else
{
MessageBox.Show("用户名不存在或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textName.Text = "";
textPass.Text = "";
}
MyClass.con_close();
}
else
{
MessageBox.Show("用户名和密码不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void F_Login_Load(object sender, EventArgs e)
{
try
{
MyClass.con_open(); //连接数据库
MyClass.con_close();
textName.Text = "";
textPass.Text = "";
}
catch
{
MessageBox.Show("数据库连接失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}
}
版主你好,在我程序中的这句
DataClass.MyMeans.Login_n = (int)(this.Tag);
报出了NullReferenceException
注:这段代码是我模仿你们的源程序写的