当前位置:Gxlcms > 数据库问题 > 数据库学习

数据库学习

时间:2021-07-01 10:21:17 帮助过:4人阅读

select MAX(age) from T_Student

 

select MIN(age) from T_Student

 

select MAX(age) as maxage, MIN(age) as minage, AVG(age), COUNT(*) from T_Student

 

select COUNT(*) from T_Student where age > 18

 

select * from T_Student where Name = ‘yzk‘

 

select * from T_Student where Name like ‘%a%‘

 

Lucene .net

 

select * from T_Student order by age asc, height desc

 

select * from T_Student where name like ‘%a%‘ order by age

 

//建立连接

using(SqlConnection conn = new SqlConnection(
"Data Source = .; Initial Catalog = AdventureWorks2012; User ID = sa; Password = 1234567890"))
{

//打开连接
conn.Open();

//通过连接创建一个向数据库发命令的对象SqlCommand
using(SqlCommand cmd = conn.CreateCommand())
{

//要执行的SQL语句
cmd.CommandText =
"insert into sales.shoppingcartitem values( ‘gongcheng‘, 1, 2, getdate(), getdate())";
cmd.ExecuteNonQuery();
}
MessageBox.Show("OK");
}

 

ExecuteScalar()一般用来执行有且只有一行一列返回值的SQL语句

ExecuteNonQuery()执行非查询

cmd.CommandText = "insert into T_Student (Name, Age) output inserted.Id valuers(‘aaa‘, 19)";

long i = (long) cmd.ExecuteScalar();

MessageBox.Show(i.ToString());

数据库学习

标签:

人气教程排行