把异常堆栈打出来看看
目前创新互联已为1000+的企业提供了网站建设、域名、虚拟空间、网站托管维护、企业网站设计、和政网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
补充:
在更新或提交的时候出现的错误,可能是某个控件的值,字符串等无法转换成数字,你检查一下是不是不小心弄错了控件了
代码如下:
/// summary
/// 连接到窗体:通过密码保护信息找回密码!
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void lbl_mibao_Click(object sender, EventArgs e)
{
Getbackpwd getbackpwd = new Getbackpwd();
getbackpwd.Show();
}
/// summary
/// 当该窗体加载时从xml文件中读取用户信息并加载到combox的Items中
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void Addresslist_Load(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(@"E:\面向对象--C#练习\通讯录\address list\address list\user.xml");
while (reader.Read())
{
//if (reader.LocalName.Equals("Name") || reader.LocalName.Equals("Number"))
if (reader.LocalName.Equals("username"))
{
this.cmbUserName.Items.Add(reader.ReadString());
}
//if (reader.LocalName.Equals("Number"))
//{
// this.label2.Text += reader.ReadString() + "\n";\
//}
}
reader.Close();
}
/// summary
/// 保存用户名到user.xml
/// /summary
//在listcontol上更改SelectedValue时执行从数据库读取密码的事件
private void cmbUserName_SelectedValueChanged(object sender, EventArgs e)
{
string username = cmbUserName.Text.Trim();
string sql = string.Format("select pwd from Admin where Username='{0}'", username);
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
txtpwd.Text = (string)dataReader["pwd"];
checkBoxpwd.Checked = true;
}
}
catch
{
MessageBox.Show("数据库操作出错!");
}
finally
{
DBHelper.connection.Close();
}
}
/// summary
/// 记住密码操作
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void checkBoxpwd_Enter(object sender, EventArgs e)
{
bool check = true;
check = checkinput(cmbUserName.Text.Trim());
if ((string)cmbUserName.Text.Trim() == "")
{
MessageBox.Show("请输入用户名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbUserName.Focus();
}
else
{
if (txtpwd.Text.Trim() == "")
{
MessageBox.Show("请输入密码", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpwd.Focus();
}
else
{
bool isValidUser = false; // 标识是否为合法用户
string message = ""; // 如果登录失败,显示的消息提示
// 如果验证通过,就显示相应的用户窗体,并将当前窗体设为不可见
if (ValidateInput())
{
// 调用用户验证方法
isValidUser = ValidateUser(cmbUserName.Text, txtpwd.Text, ref message);
// 如果是合法用户,显示相应的窗体
if (isValidUser)
{
if (check == true)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"E:\面向对象--C#练习\通讯录\address list\address list\user.xml");//(@"E:\面向对象--C#练习\通讯录\address list\address list\user.xml");
XmlElement node = doc.CreateElement("user");
XmlNode xnode = (XmlNode)doc.CreateElement("username");
xnode.InnerText = cmbUserName.Text.Trim();
node.AppendChild(xnode);
doc.DocumentElement.InsertAfter(node, doc.DocumentElement.LastChild);
doc.Save(@"E:\面向对象--C#练习\通讯录\address list\address list\user.xml");
//doc.Load (@"E:\面向对象--C#练习\通讯录\address list\address list\user.xml");
}
}
// 如果登录失败,显示相应的消息
else
{
MessageBox.Show(message, "记住密码失败!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
/// summary
/// 验证当前combox中内容是否已经存在于xml文件中
/// /summary
/// param name="text"/param
/// returns/returns
private bool checkinput(string text)
{
int count;
bool c = true;
for (count = 0; count cmbUserName.Items.Count;count ++ )
{
if (text ==(string )cmbUserName .Items [count])
{
c=false;
}
}
return c;
}
xml文件内容如下:?xml version="1.0" encoding="utf-8"?
person
user
需要连接数据库,你可以用access做个小型数据库
每次系统登录的时候,根据用户名去数据库查询密码
Private Sub BtOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btok.Click
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Admin.accdb;Persist Security Info=True")
Dim com As OleDbCommand = New OleDbCommand("select * from 用户名", con)
con.Open()
Dim h1 As OleDbDataReader
Dim table As New DataTable
h1 = com.ExecuteReader()
table.Load(h1)
If txtName.Text = "" Then
MsgBox("请输入用户名", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
ElseIf txtName.Text "" And txtPasswd.Text = "" Then
MsgBox("请输入密码", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
ElseIf table.Select("用户名='" txtName.Text "'").Length 0 Then
If table.Select("用户名='" txtName.Text "'")(0)("密码").ToString = txtPasswd.Text Then
MsgBox("成功登陆", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示") Then
Form1.Show()
Me.Visible = False
Exit Sub
Else
MsgBox("密码错误", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
End If
Else
MsgBox("用户名不存在", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
Exit Sub
End If
table.Clear()
h1.Close()
con.Close()
End Sub
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Response.Write("scriptalert('用户名或密码不能为空!')/script"); //提示对话框
}
else
{
string ConStr = "server=(local);user id=sa;pwd=123456;database=userdb";
SqlConnection con = new SqlConnection(ConStr);
string SqlStr = "select * from mymember where sname = '" + TextBox1.Text + "' and spwd = '" + TextBox2.Text + "'"; //Select查询语句
SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
con.Open(); //打开连接
DataSet ds = new DataSet();
ada.Fill(ds);
if (ds.Tables[0].Rows.Count 0)
{
Session["username"] = TextBox1.Text;
Response.Redirect("index.aspx");
}
else
{
Response.Write("scriptalert('用户名或密码错误,请重新登录!')/script");
}
} //绑定GridView控件
}
做不到,access数据库是本地数据库,不支持网络访问,建议你换成sql server或者mysql之类的数据库。
注:如果一定要远程访问access也不是不行,有两种办法,一个是服务器如果跟你在同一个局域网,可以把数据库文件夹共享出来,当做共享文件访问。另一种是在那台服务器上装个sql server数据库,sql server可以创建出链接数据库链接到那个access.