unity3D---SQL

本文将介绍如何在Unity3D游戏中集成SQLite数据库,包括安装必要的库、创建数据库连接、执行SQL查询以及在游戏逻辑中使用数据库存储和检索数据的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、查询全部

select*from  users

2、查询部分数据

select id name from users where name='zhangsan'

3、去掉重复字段查询记录(这是针对一个字段,不能十多个)

select distinct name from

4、合并查询(合并两表中相同的字段)

select*from users union select*from score

5、用AS来命名列

select id as 编号,name as 姓名 from users

6、用=来命名列

select ‘编号’=id,‘姓名’=name from users

7、查询空行

select name from users where password is null

8、查询非空行

select name from users where name is not null

9、使用常量列

select 姓名=name,‘密码’as password from users

10、限制固定行数

select top 3*from users

11、返回百分之多少行

select top 20 percent *from users

12、升序

select*from users order by id


select*from users order by id asc

13、降序

select*from users order by id desc

14、按多列排序(当排序的值相同时,按第二个字段排序)

select *from users order by name,id

*连接数据库*
程序访问数据库的步骤



程序访问数据库的步骤

public void Get
 {
           SqlConnection con = new SqlConnection("server=127.0.0.1;uid =
                                              sa; pwd =wang;database =second");
           SqlCommand cmd=new SqlCommand("select * from users",con);
 con.Open();
                SqlDataReader myreader=cmd.ExecuteReader();
           while (myreader.Read())
            {
                Console.WriteLine(myreader.GetValue(0) + "   " + 
                myreader.GetValue(1));  
            }
            myreader.Close();
            con.Close();
          }

插入功能

 public int insert(){
            SqlConnection con = new SqlConnection("server=127.0.0.1;uid =
                                            sa; pwd =wang;database =second");
            string sql = "insert into users(name,password) values('王五','789')";
            SqlCommand comm = new SqlCommand(sql, con);
            con.Open();
            int count = comm.ExecuteNonQuery();
            return count;
        }


查询功能

 public List<Users> select() {
            List<Users> list = new List<Users>();
            SqlConnection con = new SqlConnection("server=127.0.0.1;uid =
                                              sa; pwd =wang;database =second");
            SqlCommand cmd = new SqlCommand("select * from users", con);
            con.Open();
            SqlDataReader myreader = cmd.ExecuteReader();
           while (myreader.Read())
           {
                Users u = new Users();
               u.Id =(int) myreader.GetValue(0);
                u.Name =(string) myreader.GetValue(1);
                u.Password = (string)myreader.GetValue(2);
               list.Add(u);
           }


更多精彩请关注:http://www.gopedu.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值