您的位置:首页 > 博客中心 > 数据库 >

unity3d怎么连接sql server数据库?

时间:2022-03-10 18:05

1、找到System.Data.dll文件,默认的地址是在C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity,这个根据你所安装的路径有关。

 gxlsystem.com,布布扣

gxlsystem.com,布布扣

4、在命名空间内增加程序集

  using System;

  using System.Data;

  using System.Data.SqlClient;

  5、编写连接数据库代码

  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、实验结果

gxlsystem.com,布布扣

unity3d怎么连接sql server数据库?,布布扣,bubuko.com

热门排行

今日推荐

热门手游