namespace database1
{
using System;
using System.Data.ADO;
public class Class1
{
public Class1()
{
//
// 在这里添加Constructor的逻辑
//
}
public static int Main(string[] args)
{
try
{
ADOConnection s = new ADOConnection("Data Source=mymdb");
s.Open();
Console.WriteLine("Connection Established");
//创建表
Console.Write("Want to Create a Table?(y/n) ");
string ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand CreateTable = new ADOCommand("Create Table a1(vno integer,name char(20))", s);
CreateTable.ExecuteNonQuery();
Console.WriteLine("AOCommand Executed / Table Created");
}
//在表中插入值
Console.Write("Want to Insert Some values in a Table?(y/n) ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand InsTable = new
ADOCommand("insert into a1 values(1, 'hi')", s);
InsTable.ExecuteNonQuery();
Console.WriteLine("Values Inserted");
}
//删除整个表
Console.Write("Want to Delete All Records Present in the Table?(y/n) ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand DeleteTable = new ADOCommand("Delete from a1", s);
DeleteTable.ExecuteNonQuery();
Console.WriteLine("All Records Deleted From the Table");
}
//看所有记录
Console.Write("Want to See all the Records Present in the Table /Database (y/n)? ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand AllRecs = new ADOCommand("select * from a1", s);
ADODataReader r;
AllRecs.Execute(out r);
while(r.Read())
{
for(int i=0; i < r.FieldCount;i++)
{
Console.Write(r.GetValue(i)+ " ");
}
Console.WriteLine();
}
Console.WriteLine("All Records Displayed");
r.Close();
}
s.Close();
Console.ReadLine();
}
catch(System.Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
return 0;
} // Main函数结束
} // Class结束
}// 名字空间结束
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有