static void Main(string[] args)
{ string sqlstr = "select * from manavatar"; MySQLConnection DBConn = new MySQLConnection(new MySQLConnectionString("192.168.0.13", "flashdata", "root", "root", 3306).AsString); DBConn.Open(); //MySQLDataAdapter myadap = new MySQLDataAdapter(sqlstr, conn); MySQLCommand DBComm = new MySQLCommand(sqlstr,DBConn); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); //DBComm.ExecuteReaderEx(); MySQLDataAdapter DTAdapter = new MySQLDataAdapter(sqlstr,DBConn); DataSet myDataSet = new DataSet(); DTAdapter.Fill(myDataSet,"manavatar"); try { while (DBReader.Read()) { //Console.WriteLine("11"); Console.WriteLine("DBReader:{0},\t\t\tddddd:{1},\t\t {2}",DBReader.GetString(0), DBReader.GetString(1),DBReader.GetString(3)); } Console.WriteLine("0000"); } catch (Exception e) { Console.WriteLine("讀入失??!"+e.ToString()); } finally { Console.WriteLine("DBReader關(guān)閉"); Console.WriteLine("DBConn關(guān)閉"); DBReader.Close(); //DBConn.Close(); } for (int i = 0; i < myDataSet.Tables["manavatar"].Rows.Count; i++) { Console.WriteLine("{0}",myDataSet.Tables["manavatar"].Rows[2]["user"]); } } 這是一個簡單的例子。 在這里有個問題:dataset如果沒設(shè)主鍵的話,可能會引起一些對數(shù)庫操作的問題,比如會造成updata出現(xiàn)錯誤。 |
|
來自: levenstein > 《C#》