using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace wlw_database
{
public partial class Form1 : Form
{
SqlConnection MyConnect = new SqlConnection ();
public Form1()
{
InitializeComponent();
}
private void OpenDatabase_Click(object sender, EventArgs e)
{
MyConnect.ConnectionString = "Data Source=(local); Initial Catalog=物联网; User ID= gly; Password=123456";
MyConnect.Open();
MessageBox.Show("打开数据库成功");
}
private void CloseDatabase_Click(object sender, EventArgs e)
{
MyConnect.Close();
MessageBox.Show("关闭数据库成功");
}
private void CreateTable_Click(object sender, EventArgs e)
{
SqlCommand CreateTableCmd = new SqlCommand();
CreateTableCmd.Connection = MyConnect;
CreateTableCmd.CommandType = CommandType.Text;
CreateTableCmd.CommandText = "CREATE TABLE Student(Stu_ID nchar(8) not null Primary Key,Name nvarchar(20) not null,Sex nchar(2) not null,Adress nvarchar(50) not null,Class_Code nchar(4))";
// CreateTableCmd.ExecuteScalar();
CreateTableCmd.CommandText = "CREATE TABLE Teacher(Teacher_ID nchar(8) not null Primary Key,Name nvarchar(20) not null,phone nchar(20) not null,Subject nchar(20) not null,Commot nchar(200) not null)";
// CreateTableCmd.ExecuteScalar();
CreateTableCmd.CommandText = "CREATE TABLE Subject(ID nchar(8) not null Primary Key,Subject nvarchar(20) not null,Start_Lesson nchar(40) not null)";
// CreateTableCmd.ExecuteScalar();
CreateTableCmd.CommandText = "CREATE TABLE Grade(ID nchar(8) not null Primary Key,Name nvarchar(8) not null,Subject nvarchar(20) not null,Grade nchar(40) not null)";
// CreateTableCmd.ExecuteScalar();
CreateTableCmd.CommandText = "CREATE TABLE Addrbook(Name nvarchar(8) not null,Phone nvarchar(20) not null,qq nchar(12) not null,Address nchar(40) not null)";
CreateTableCmd.ExecuteScalar();
MessageBox.Show("创建表成功");
}
private void DropTable_Click(object sender, EventArgs e)
{
SqlCommand CreateTableCmd = new SqlCommand();
CreateTableCmd.Connection = MyConnect;
CreateTableCmd.CommandType = CommandType.Text;
CreateTableCmd.CommandText = "Drop TABLE student";
CreateTableCmd.ExecuteScalar();
MessageBox.Show("删除表成功");
}
}
}
阅读(1949) | 评论(0) | 转发(0) |