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

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

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

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

1、找到System.Data.dll文件,默認(rèn)的地址是在C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity,這個(gè)根據(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ù)庫(kù)代碼

SqlConnection con = null;    SqlDataAdapter sda = null;    void Start()    {        string s = @"server=.;database=ConnectTest;uid=sa;pwd=123456";    //注意,這里必須使用SQL Server和Windows驗(yàn)證模式,否則會(huì)報(bào)錯(cuò)        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、實(shí)驗(yàn)結(jié)果

相關(guān)文章

最新評(píng)論