//存入
string con = "Server=.;Database=UsersInfo;integrated security=SSPI";
SqlConnection mycon = new SqlConnection(con); mycon.Open(); using (SqlCommand cmd = mycon.CreateCommand()) { cmd.CommandText = "select * from loginInfo where Account='" + account + "'"; SqlDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) { reader.Close(); cmd.CommandText = "insert into loginInfo(Account,PassWord) values('" + account + "','" + passwordonce + "')"; cmd.ExecuteNonQuery(); MessageBox.Show("注册成功"); this.Close(); } else { MessageBox.Show("帐号已存在"); } } con.Clone();
//读取
string con; con = "Server=.;Database=UsersInfo;integrated security=SSPI"; SqlConnection mycon = new SqlConnection(con); mycon.Open(); using (SqlCommand cmd = mycon.CreateCommand()) { cmd.CommandText = "select * from loginInfo where Account='" + account + "'"; using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { if (reader.Read()) { string Password = reader.GetString(reader.GetOrdinal("Password")); if (password == Password) { MessageBox.Show("登陆成功"); mycon.Close(); writeInPas(); //储存当前帐号 StreamWriter sw = new StreamWriter(application.StartupPath + "//tmpAccount.txt", false); sw.WriteLine(txtAccountLgn.Text); sw.Close(); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("用户名或密码错误"); } } } else { MessageBox.Show("用户名或密码错误"); } } }
新闻热点
疑难解答