登陆窗体
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.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
register register = new register();
register.Show();
}
private void button1_Click(object sender, EventArgs e)
{
string qq = textBox1.Text;
string password = textBox2.Text;
string connStr = "Data Source=.;Initial Catalog=User;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
if (conn.State == ConnectionState.Open)
{
string sql = "select *from User1 where ID='" + qq + "' and Password='" + password + "'";
SqlCommand command = new SqlCommand(sql, conn);
SqlDataReader dataReader = command.ExecuteReader();
if (dataReader.HasRows)
{
MessageBox.Show("登录成功!");
}
else
{
textBox1.Text="";
textBox2.Text="";
MessageBox.Show("登录失败,账号或密码错误!");
}
}
conn.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
注册窗体
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.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class register : Form
{
public register()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string qq = textBox1.Text;
string password = textBox2.Text;
string connStr = "Data Source=.;Initial Catalog=User;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
if (conn.State == ConnectionState.Open)
{
string sql = "insert into User1 values ('" + qq + "','" + password + "')";
SqlCommand command = new SqlCommand(sql, conn);
int num = command.ExecuteNonQuery();
if (num > 0)
{
MessageBox.Show("新增成功");
}
else
{
MessageBox.Show("新增失败");
}
conn.Close();
}
}
private void register_Load(object sender, EventArgs e)
{
}
}
}