`
ljl_xyf
  • 浏览: 618660 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

C#里 如何序列化与反序列化 hashtable Dictionary及C#连接mysql数据库

    博客分类:
  • c#
 
阅读更多

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

Hashtable aa = new Hashtable();

private void buttonSave_Click(object sender, EventArgs e)
{
 FileStream fs = new FileStream("e:\\400tel .dat", FileMode.Create);
 BinaryFormatter bf = new BinaryFormatter();
 bf.Serialize(fs, aa);
 fs.Close();
}

private void buttonLoad_Click(object sender, EventArgs e)
{
 aa.Clear();
 FileStream fs = new FileStream("e:\\400tel.dat", FileMode.OpenOrCreate);
 BinaryFormatter bf = new BinaryFormatter();
 aa = (Hashtable)bf.Deserialize(fs);
 fs.Close();

}

 

   //Dictionary<String, String> dic = new Dictionary<String, String>(13000000);

C#连接mysql数据库

string ConnectionString = "server = localhost; user id = XXXX; password = XXXX; database = XXXX";
string sqlString="......(此处sql语句省略)";
using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand(sqlString, connection))
                {
                    try
                    {
                        connection.Open();
                        int rows = cmd.ExecuteNonQuery();//执行sql语句
                        return rows;
                    }
                    catch (MySql.Data.MySqlClient.MySqlException e)
                    {
                        connection.Close();
                        throw e;
                    }
                }
            }

 

 

 

 

 

 

 

 

 

下载 mysql-connector-net-6.4.3.rar

下载 mysql-connector-net-6.4.3-src.zip

 

 


 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics