欢迎光临
我们一直在努力

c#连接mysql _c#应用

建站超值云服务器,限时71元/月

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关闭”);
                Console.WriteLine(“DBConn关闭”);
                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如果没设主键的话,可能会引起一些对数库操作的问题,比如会造成updata出现错误。


http://www.cnblogs.com/sopper/archive/2007/01/02/610142.html

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » c#连接mysql _c#应用
分享到: 更多 (0)