添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
--创建数据库 IF NOT EXISTS(SELECT * FROM dbo.sysdatabases WHERE [name]='TestDB') CREATE DATABASE TestDB; --使用数据库 USE TestDB; --创建用户表 IF EXISTS(SELECT * FROM sysobjects WHERE [name]='Users') DROP TABLE [Users] CREATE TABLE [Users]( [Id] [int] IDENTITY(1,1),--主键 [Name] [nvarchar](50) NOT NULL,--姓名 [Sex] [nvarchar](10),--性别 PRIMARY KEY([Name]) INSERT INTO [Users]([Name],[Sex]) VALUES ('Alice','Female'); INSERT INTO [Users]([Name],[Sex]) VALUES ('Amy','Female'); INSERT INTO [Users]([Name],[Sex]) VALUES ('Bruce','Male');         static void Main(string[] args) string connectionString = "Data Source=127.0.0.1,1433;Initial Catalog=TestDB;uid=sa;pwd=123456"; string sqlstring = "DELETE FROM [Users] WHERE [Name]='Alice';"; using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlCommand cmd = new SqlCommand()) conn.Open(); cmd.Connection = conn; cmd.CommandText = sqlstring; cmd.CommandType = System.Data.CommandType.Text;                         // 返回受影响的行数, 执行INSERT语句, 返回创建条目数                         //                  执行UPDATE语句, 返回更新条目数                         //                  执行DELETE语句, 返回删除条目数                         int val = cmd.ExecuteNonQuery(); Console.WriteLine(val); catch throw; Console.Read();