欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

unity3d怎么連接sql server數(shù)據(jù)庫

  發(fā)布時間:2013-11-18 13:46:15   作者:佚名   我要評論
雖然在Unity3D中能夠通過PlayerPrefs類來保存和讀取數(shù)據(jù),但是一旦數(shù)據(jù)量增大,僅僅通過代碼的方式存取數(shù)據(jù),這樣的工作量是非常大的

雖然在Unity3D中能夠通過PlayerPrefs類來保存和讀取數(shù)據(jù),但是一旦數(shù)據(jù)量增大,僅僅通過代碼的方式存取數(shù)據(jù),這樣的工作量是非常大的。那么如何通過使用Sql Server數(shù)據(jù)庫來存取數(shù)據(jù)呢?其實過程也非常簡單,過程如下:

1、找到System.Data.dll文件,默認(rèn)的地址是在C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity,這個根據(jù)你所安裝的路徑有關(guān)。

2、將該文件復(fù)制到你的工作空間下的Asset文件夾內(nèi)

3、在你的編輯器中添加引用,我用的是VS

4、在命名空間內(nèi)增加程序集

using System;

using System.Data;

using System.Data.SqlClient;

5、編寫連接數(shù)據(jù)庫代碼

SqlConnection con = null;    SqlDataAdapter sda = null;    void Start()    {        string s = @"server=.;database=ConnectTest;uid=sa;pwd=123456";    //注意,這里必須使用SQL Server和Windows驗證模式,否則會報錯        con = new SqlConnection(s);        con.Open();        string sql = "select * from table1";        sda = new SqlDataAdapter(sql, con);        DataSet ds = new DataSet();        sda.Fill(ds, "table1");        print(ds.Tables[0].Rows[0][0]);    }

6、實驗結(jié)果

相關(guān)文章

最新評論