/ Published in: C#
Expand |
Embed | Plain Text
using System.Data; using MySql.Data.MySqlClient; public void dbStuff() { String strSQL; String strConn; MySqlCommand myCommand; strConn = "SERVER=localhost;" + "port=3306;" + "database=mydatabase;" + "user id=youUName;" + "password=YourPW;"; //Open connection to DB. try{myConnection.Open();} catch (Exception e) { trace(e.ToString()); } //Insert data to DB, or what ever you want to do. strSQL = "INSERT INTO mytable (int_field, text_field, date_field) Values (16, 'Lorum ibsum' , '2012-12-21');"; myCommand.ExecuteNonQuery(); //Read data from DB. try { MySqlDataReader myReader = null; strSQL = "select * from mytable"; myReader = myCommand.ExecuteReader(); while (myReader.Read()) { trace(myReader["int_field"].ToString()); trace(myReader["text_field"].ToString()); } } catch (Exception e) { trace(e.ToString()); } //Close connection to DB. try {myConnection.Close();} catch (Exception e) { trace(e.ToString()); } } public void trace(String s) { out1.Text += s + "<br />"; //out1 is a Literal }
You need to login to post a comment.
