Untitled
unknown
plain_text
a year ago
2.0 kB
7
Indexable
using System.Data; namespace SF_Aguila_285 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string ConnString = @"SERVER=localhost; DATABASE=tinycollegelibrary; UID=root; PWD=;"; private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { //1. Connect with Database MySqlConnection Conn = new MySqlConnection(ConnString); string sSQL = ""; DataTable dt = new DataTable(); //Hold records from table try { Conn.Open(); //Establish connection with MySql //2. Setup command MySqlCommand cmd = new MySqlCommand(); cmd.Connection = Conn; cmd.CommandType = CommandType.Text; sSQL = "SELECT * FROM tblbooks"; //SQL Query cmd.CommandText = sSQL; //3. Data Reader MySqlDataReader dr = cmd.ExecuteReader(); dt.Load((IDataReader)dr); //Transfer DataReader(dr) data to DataTable(dt) dataGridView1.DataSource = dt; //Show data into DataGridView Conn.Close(); } catch { MessageBox.Show("Connection Error!"); return; } } private void btnSearch_Click(object sender, EventArgs e) { txtISBN.Text = ""; txtTitle.Text = ""; txtAuthor.Text = ""; LoadData(); } private void LoadData() { throw new NotImplementedException(); } } }
Editor is loading...
Leave a Comment