zoukankan      html  css  js  c++  java
  • C#显示SQL语句格式

    --SQL SERVER生成测试环境:

    Create database Test; 
    go
    USE [Test]
    GO
    
    if OBJECT_ID('Tab','U') is not null
    	drop table Tab
    go
    CREATE TABLE [dbo].[Tab](
    	[ID] [int] NOT NULL  CONSTRAINT [PK_Tab] PRIMARY KEY CLUSTERED ,
    	[name] [sysname] NOT NULL
    )
    
    


    --打开Visual Studio—创建项目—选择【控制台应用程序】

    #region Using Directives
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    #endregion
    
    namespace TestShowSql
    {
        class Program
        {
            static void Main(string[] args)
            {
                SqlConnection thisConnection = new SqlConnection(@"Server=(Local);Integrated Security=True;Database=Test");
                //thisConnection.Open();
                SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT ID,NAME FROM TAB",thisConnection);
                SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
                Console.WriteLine("SQL Select Command is :
    {0}
    ", thisAdapter.SelectCommand.CommandText);
                SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
                Console.WriteLine("SQL UPDATE Command is :
    {0}
    ",updateCommand.CommandText);
                SqlCommand insertCommand = thisBuilder.GetInsertCommand();
                Console.WriteLine("SQL INSERT Command is :
    {0}
    ",insertCommand.CommandText);
                SqlCommand deleteCommand = thisBuilder.GetDeleteCommand();
                Console.WriteLine("SQL DELETE Command is :
    {0}
    ",deleteCommand.CommandText);
                thisConnection.Close();
                Console.WriteLine("Program finished,Press Enter/Return to continue:");
                Console.ReadLine();
            }
        }
    }
    


    --按F5运行结果:

  • 相关阅读:
    P7003 [NEERC2013]Hack Protection
    P6753 [BalticOI 2013 Day1] Ball Machine
    笛卡尔树-P2659 美丽的序列
    [省选联考 2020 A/B 卷] 冰火战士
    CF1166E The LCMs Must be Large
    线段树标记永久化模板
    zoj 2112 单点修改的主席树(树状数组套主席树)
    poj 2104 无修改主席树
    python中map的排序以及取出map中取最大最小值
    python之禅
  • 原文地址:https://www.cnblogs.com/Roy_88/p/5463040.html
Copyright © 2011-2022 走看看