十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Dim sql As String = "Update userTable Set 密码='" TextBox2.Text " ' where 用户名='" ursename "'"
成都创新互联专业为企业提供环江网站建设、环江做网站、环江网站设计、环江网站制作等企业网站建设、网页设计与制作、环江企业网站模板建站服务,十余年环江做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
以下这里有错误:
Dim mysqlstr As String = "SELECT * FROM 登录表 WHERE users='" username " 'AND password='" userpassword " '"
修改为:
Dim mysqlstr As String = "SELECT * FROM 登录表 WHERE users='" username "' AND password='" userpassword "'"
首先在项目的VB.NET界面,使用菜单【项目】--【添加引用】--【COM】
选择 Microsoft ADO Ext. 2.x for DDL and Security
然后单击【确定】,完成引用。
完整代码如下:
Imports ADOX
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建空的access数据库文件--数据库文件.mdb,密码为123
Dim Mycat As Catalog = New Catalog()
Mycat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source= 数据库文件.mdb;Jet OLEDB:Database Password=123")
'以下代码创建一个名为“实验数据表”
Dim MyTable As ADOX.Table = New ADOX.Table '定义新表
MyTable.Name = "实验数据表" '表命名
'给表“实验数据表” 创建一个字符串字段,字段名“姓名”
MyTable.Columns.Append("姓名", , ADOX.DataTypeEnum.adWChar)
'给表“实验数据表” 创建一个整数字段,字段名“学号”
MyTable.Columns.Append("学号", ADOX.DataTypeEnum.adInteger) '追加一个数字型字段
'给字段“学号”创建一个主键“PimaryKey_Field”
MyTable.Keys.Append("学号", ADOX.KeyTypeEnum.adKeyPrimary, "学号")
Mycat.Tables.Append(MyTable) '把所有的新字段追加到表
MyTable = Nothing
Mycat = Nothing
End Sub
End Class
代码如下:
/// 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