String strConnString; strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"; objConn = new MySqlConnection(strConnString); objConn.Open(); if(objConn.State == ConnectionState.Open) { this.lblText.Text = "MySql Connected"; } else { this.lblText.Text = "MySql Connect Failed"; }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using MySql.Data.MySqlClient; using System.Windows.Forms; namespace WindowsFormsApplication15 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } public bool tryLogin(string username, string password) { MySqlConnection con = new MySqlConnection("Server=localhost;user=root;password=042511827; database=voiceoperation;"); MySqlCommand cmd = new MySqlCommand("SELECT * FROM login_test WHERE user_name = '" + username + "' AND user_pass = '" + password + "';"); cmd.Connection = con; con.Open(); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read() != false) { if (reader.IsDBNull(0) == true) { cmd.Connection.Close(); reader.Dispose(); cmd.Dispose(); return false; } else { cmd.Connection.Close(); reader.Dispose(); cmd.Dispose(); return true; } } else { return false; } } private void button3_Click(object sender, EventArgs e) { if (tryLogin(txtuser.Text, txtpass.Text) == true) { MessageBox.Show("Authed!"); } else { MessageBox.Show("Auth Failure."); } } } }
private void Form1_Load(object sender, EventArgs e) { String strConnString; strConnString = "Server=localhost;User Id=root; Password=042511827; Database=voiceoperation; Pooling=false"; objConn = new MySqlConnection(strConnString); objConn.Open(); if (objConn.State == ConnectionState.Open) { this.lblText.Text = "MySql Connected"; } else { this.lblText.Text = "MySql Connect Failed"; } } void Form1_UnLoad() { objConn.Close(); objConn = null; }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง