//查询 private void button2_Click(object sender, EventArgs e) { 注册 a1 = new 注册(); if (a1.check_textbox(textBox1, textBox2)) { try { string mystr = string.Format("select * from {0}", textBox2.Text.Trim()); string lian_jie = string.Format("server=localhost;port=3306;database={0};user={1};password={2};charset=utf8;", textBox1.Text.Trim(), mysql账号密码.use, mysql账号密码.password); DataSet myds = new DataSet(); MySqlConnection conn = new MySqlConnection(lian_jie); conn.Open(); if (conn.State == ConnectionState.Open) { MySqlDataAdapter myad = new MySqlDataAdapter(mystr, conn); myad.Fill(myds, textBox2.Text.Trim()); dataGridView1.DataSource = myds.Tables[textBox2.Text.Trim()]; } else { MessageBox.Show("连接失败", "提示", MessageBoxButtons.OK); } } catch (Exception err) { MessageBox.Show("错误为:" + err.Message, "提示", MessageBoxButtons.OK); } } }
//登录 private void ucBtnExt1_BtnClick(object sender, EventArgs e) { try { 注册 aa = new 注册(); if (check_textbox(ucTextBoxEx1, ucTextBoxEx2)) { string use = ucTextBoxEx1.InputText; string password = ucTextBoxEx2.InputText; string conn = "server=localhost;port=3306;database=hmmap;user=root;password=jhm19980613;charset=utf8;"; string sql = string.Format("select * from user where name='{0}' and password='******'", use, password); MySqlConnection lianje = new MySqlConnection(conn); lianje.Open(); MySqlCommand mcd = new MySqlCommand(sql, lianje); MySqlDataReader mdr = mcd.ExecuteReader(); if (mdr.Read()) { Program.Login = 1; this.Close(); } else { MessageBox.Show("用户名或者密码错误,请重新登陆。", "提示", MessageBoxButtons.OK); } } } catch (Exception arr) { MessageBox.Show("错误" + arr.Message); } }
private void button1_Click(object sender, EventArgs e) { 注册 aa = new 注册(); try { if (aa.check_textbox(textBox1, textBox2)) { use = textBox1.Text.Trim(); password = textBox2.Text.Trim(); string conn = string.Format("server=localhost;port=3306;database=text_database;user={0};password={1};charset=utf8;", use, password); MySqlConnection lianjie_state = new MySqlConnection(conn); lianjie_state.Open(); if (lianjie_state.State == ConnectionState.Open) { label3.Text = "数据库连接成功"; } else { label3.Text = "数据库连接失败!"; } } } catch (Exception arr) { label3.Text = "数据库连接失败!"; MessageBox.Show("错误:" + arr.Message); } }
//注册 private void label4_Click(object sender, EventArgs e) { Form region = new 注册(); region.ShowDialog(); }