Uinty3D学习基础知识 数据库连接
来源:互联网 发布:java模拟http上传文件 编辑:程序博客网 时间:2024/06/07 13:29
select * from users
2. 查询部分行
select id,name from users where name='张三'
select id,name from users where name<>'张三'
3.去掉重复字段查询记录
select distinct name from users
4.合并查询(合并两表中相同的字段)所查字段要类型相同
select id from users union select id from score
5. 用AS来命名列
select id as 编号,name as 姓名 from users
6. 用 = 来命名列
select 编号 =id ,姓名=name from users
select '编号' =id ,'姓名'=name from users
7.查询空行
select id, name from users where password is null
8.查询非空行
select name from users where name is not null
9.使用常量列(默认值)
select name as 姓名 ,'密码' as password from users
10.限制固定行数
select top 3 * from users
11. 返回百分之多少行
select top 50 percent * from users
12. 排序
SELECT <列名> FROM <表名> [WHERE <查询条件表达式>] [ORDER BY <排序的列名>[ASC或DESC]]
asc:升序 desc:降序
升序
select * from users order by id
select * from users order by id asc
降序
select * from users order by id desc
按多列排序(当排序的值相同时,按第二个字段排序)
select * from users order by name,id
- public void Get()
- {
- SqlConnection con = new SqlConnection("server=.;database =users;Trusted_Connection=SSPI");
- SqlCommand cmd=new SqlCommand("select * from teacher",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=.;database =users;Trusted_Connection=SSPI");
- string sql = "insert into teacher(name,age,id) values('赵六',23,114)";
- SqlCommand comm = new SqlCommand(sql, con);
- con.Open();
- int count = comm.ExecuteNonQuery();
- return count;
- }
{
public string name;
{
this.name = name;
}
public string Getname()
{
return name;
}
public int age;
public void Setage(int age)
{
this.age = age;
public int Getage()
{
return age;
}
public int id;
{
set { id = value; }
get { return id; }
}
}
public List<People> select()
{
List<People> list = new List<People>();
SqlConnection con = new SqlConnection("server=.;database=Joker;Trusted_Connection=SSPI");
- con.Open();
SqlCommand com = new SqlCommand("select*from teacher",con);
SqlDataReader myreader = com.ExecuteReader();
while (myreader.Read())
{
People p = new People ();
p.Id=(int)myreader.GetValue(0);
p.Setname ((string)myreader.GetValue(1));
p.Getname();
p.Setage((int)myreader.GetValue(2));
p.Getage();
list.Add(p);
}
myreader.Close();
- con.Close();
return list;
foreach (People p in list)
{
Console.WriteLine(p.Getname()+" "+p.Getage()+" "+p.Id);
}
}
{
Class3 a = new Class3();
a.select();
a.Get();
IEnumerator<People> it = list.GetEnumerator();
while (it.MoveNext())
{
Console.WriteLine(it.Current.Getage()+" "+it.Current.Getname ()+" "+it.Current.Id);
}
- Uinty3D学习基础知识 数据库连接
- uinty3D学习C#基础语言
- PostgreSQL入门学习之数据库连接相关基础知识
- uinty3d 存档
- JDBC 基础知识(一) + 各种数据库连接
- Uinty3D 资源&&教程收集
- uinty3d--GameObject与Transform
- uinty3d之触摸(一)
- Uinty3D中协程&多线程&异步区别
- uinty3d之触摸(一)
- dw中数据库连接及一些基础知识
- Delphi7学习(数据库连接操作)
- java学习笔记 数据库连接
- 数据库连接池的学习
- Oracle学习—数据库连接
- Java数据库连接池学习
- 数据库连接池C3P0学习
- Java数据库连接池学习
- SCAN线性时间社区发现算法在SNAP上的实现
- Opengl 导入3Dmax制作的.3ds模型 并显示出来
- Boost智能指针——shared_ptr
- IP SLA route-map中常用,是个路由控制的小脚本
- 【Objective-C】06-OC对象中的self
- Uinty3D学习基础知识 数据库连接
- 黑马程序员-JAVA的多态性
- C语言指针传递与值传递
- TC(SRM)和CF入门教程for ACMer
- 发髻上发生的后果就是的规划
- 两个复数相加和两个复数相减
- 世界上顶级英文歌曲
- iOS APP在模拟器上的安装
- 【后缀数组】【poj 2406】Power Strings