--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 :\n{0}\n", thisAdapter.SelectCommand.CommandText);
SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
Console.WriteLine("SQL UPDATE Command is :\n{0}\n",updateCommand.CommandText);
SqlCommand insertCommand = thisBuilder.GetInsertCommand();
Console.WriteLine("SQL INSERT Command is :\n{0}\n",insertCommand.CommandText);
SqlCommand deleteCommand = thisBuilder.GetDeleteCommand();
Console.WriteLine("SQL DELETE Command is :\n{0}\n",deleteCommand.CommandText);
thisConnection.Close();
Console.WriteLine("Program finished,Press Enter/Return to continue:");
Console.ReadLine();
}
}
}

--按F5运行结果:

C#显示SQL语句格式的更多相关文章

  1. mybatis配置log4j显示sql语句

    log4j.properties文件下: log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4 ...

  2. mybatis显示sql语句 log4j.properties配置文件

    log4j.properties配置如下: 将ibatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: ### 设置Logger输出级别和输出目的地 # ...

  3. MiniProfiler.3.0.10 用于MVC4.0中不能显示SQL语句

    MiniProfiler.3.0.10 用于MVC4.0中可以显示执行时间,但是不能显示SQL语句,怎么解决?

  4. django显示SQL语句

    django显示SQL语句 有时候我们使用模型查询数据,但是并不知道具体执行的SQL语句到底对不对.那么可以通过下面的方法打印出具体执行的SQL语句.这样有助于调试: queryset = MyMod ...

  5. ibatis/mybatis显示sql语句 log4j.properties配置文件

    将ibatis/mybatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: ### 设置Logger输出级别和输出目的地 ### log4j.rootL ...

  6. 在hibernate框架中配置显示sql语句

    使用Hibernate的框架开发时,可在Hibernate.cfg.xml中加上 <property name="hibernate.show_sql">true< ...

  7. 在springboot 和 mybatis 项目中想要显示sql 语句进行调试

    在springBoot+Mybatis日志显示SQL的执行情况的最简单方法就是在properties新增: logging.level.com.dy.springboot.server.mapper= ...

  8. Cakephp在Controller中显示sql语句

    Cakephp在Controller中查询语句一般是: $this->Model->find(); 那么这条语句对应的sql语句是什么呢? 可以通过下面方法显示: 1. $dbo = Co ...

  9. mybatis使用用stdout-logging日志显示sql语句

    在开发中,我们很多时候需要知道当前执行的sql语句是什么样的,但是默认mybatis是不显示sql的,此时我们就可以使用stdout-logging了.1.创建mybatis-config.xml文件 ...

随机推荐

  1. [函数] Unicode 检查字符串是否含中文字

    // 字串含中文 by Aone function IsIncludeChinese(Str: String): Boolean; var i: Integer; UCS4Str: UCS4Strin ...

  2. 使用exe4j打包Java程序

    工具: exe4j软件(云盘存) 可以运行的Java程序的jar包 打开我们已经安装好的exe4j软件,首先看到的是一个欢迎界面,我们直接[next]就可以了: 2 在第二步中我们选择[JAR in ...

  3. 框架Spring笔记系列 一 基础

    主题:Spring 1.什么样的问题,使得Spring框架应用而生?使用Spring解决了那些问题? 2.

  4. 泛函编程(26)-泛函数据类型-Monad-Applicative Functor Traversal

    前面我们讨论了Applicative.Applicative 就是某种Functor,因为我们可以用map2来实现map,所以Applicative可以map,就是Functor,叫做Applicat ...

  5. CI框架源码阅读笔记1 - 环境准备、基本术语和框架流程

    最开始使用CI框架的时候,就打算写一个CI源码阅读的笔记系列,可惜虎头蛇尾,一直没有行动.最近项目少,总算是有了一些时间去写一些东西.于是准备将之前的一些笔记和经验记录下来,一方面权作备忘,另一方面时 ...

  6. SQL 行列转换简单示例

    SQLSERVER 2005 以后提供了新的方式进行行列转换,下面是一个实例供参考: if object_id('tb') is not null drop table tbTest go ),季度 ...

  7. JQuery强化教程 —— jQuery Easing

    从jQuery API 文档中可以知道,jQuery自定义动画的函数.animate( properties [, duration] [, easing] [, complete] )有四个参数: ...

  8. oracle应该安装在什么版本的linux下

    今天想在我的ubuntu上安装oracle 11g r2,在网上所有了一些教程,然后找到了oracle官网网站的Operating System Requirements,内容如下: Operatin ...

  9. word第二讲(0806)

    word里的长度单位 绝对长度单位(厘米,英寸) 相对长度单位(字符,像素) 样式 问题: 如何设置多个部分的格式 多次选择,多次设置 多次选择,一次设置 应用格式刷(ctrl+shift+c,ctr ...

  10. Android NDK目录介绍

    交叉编译 在一个平台上去编译另一个平台上可以执行的本地代码 cpu平台---arm x86 mips 操作系统平台---windows linux mac os 原理 模拟不同平台的特性去编译代码 j ...