1、创建数据库表exam
创建数据库表exam
2、数据库表插入记录
数据库表插入记录
3、编写查询SQL语句并执行
SELECT
c_number 学号,
c_name 姓名,
AVG(c_grade) 平均成绩
FROM
exam
GROUP BY
c_number,
c_name
HAVING
AVG(c_grade) >80
编写SQL语句并执行
Create table EXAM_USER(
USER_ID varchar(7) primary key,
USER_NAME varchar(10) not null,
USER_PWD varchar(20) not null,
SEX char(2) check(SEX='男'or SEX='女'),
AGE int check(Sage between 15 and 45)
)
先在程序中添加对MicrosoftADO
Ext
2.8的引用,然后
1234567891011121314151617181920212223string db = Application.StartupPath + @"\Exam.mdb"string connstr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}", db)ADOX.Catalog catalog = new Catalog()catalog.Create(connstr)//创建数据库using (OleDbConnection connection = new OleDbConnection(connstr)){connection.Open() OleDbCommand cmd = connection.CreateCommand() cmd.CommandText = "CREATE TABLE student(Num AUTOINCREMENT,Name TEXT(50),Birthday DateTime,CONSTRAINT table1_PK PRIMARY KEY(Num))" cmd.ExecuteNonQuery()//创建表//插入三条数据string insert = "insert into student(Name,Birthday) values('{0}',#{1}#)" cmd.CommandText = string.Format(insert,"MARY", "2016-02-14 22:04:36") cmd.ExecuteNonQuery() cmd.CommandText = string.Format(insert, "PATRICIA", "2015-02-20 18:05:27") cmd.ExecuteNonQuery() cmd.CommandText = string.Format(insert, "LINDA", "2013-10-18 05:03:28") cmd.ExecuteNonQuery() connection.Close()}//关闭数据库System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog.ActiveConnection)System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)