一切福田,不離方寸,從心而覓,感無不通。

SELECT INTO 和 INSERT INTO SELECT 两种表复制语句

Insert是T-sql中常用语句,Insert INTO table(field1,field2,…) values(value1,value2,…)这种形式的在应用程序开发中必不可少。但我们在开发、测试过程中,经常会遇到需要表复制的情况,如将一个table1的数据的部分字段复制到table2中,或者将整个table1复制到table2中,这时候我们就要使用SELECT INTO 和 INSERT INTO SELECT 表复制语句了。       1.INSERT INTO SELECT语句       语句形式为:Insert into Table2(field1,field2,…) select value1,value2,… from Table1       要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下:    —1.创建测试表     create TABLE Table1     (         a varchar(10),         b varchar(10),         c varchar(10),         CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED         (             a ASC         )     ) ON [PRIMARY]     create TABLE Table2     (         a varchar(10),         c varchar(10),         d int,         CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED         (             a ASC         )     ) ON [PRIMARY]     GO     —2.创建测试数据     Insert into Table1 values('赵','asds','90')     Insert into Table1 values('钱','asds','100')     Insert into Table1 values('孙','asds','80')     Insert into Table1 values('李','asds',null)     GO     select * from Table2     —3.INSERT INTO SELECT语句复制表数据     Insert into Table2(a, c, d) select a,c,5 from Table1     GO     —4.显示更新后的结果     select * from Table2     GO     —5.删除测试表     drop TABLE Table1     drop TABLE Table2       2.SELECT INTO FROM语句       语句形式为:SELECT vale1, value2 into Table2 from Table1       要求目标表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中。示例如下:    —1.创建测试表     create TABLE Table1     (         a varchar(10),         b varchar(10),         c varchar(10),         CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED         (             a ASC         )     ) ON [PRIMARY]     GO     —2.创建测试数据     Insert into Table1 values('赵','asds','90')     Insert into Table1 values('钱','asds','100')     Insert into Table1 values('孙','asds','80') […]

龙生   02 Feb 2016
View Details

sqlserver 自增ID插入指定数据

注意: 1.set identity_insert只对当前会话生效。 2.set identity_insert 表名 ON 设置后,必须显示指定Id,否则插入错误。如insert into table_name values('111')将报错。    向自增ID插入指定值。 报错:“当 IDENTITY_INSERT 设置为 OFF 时,不能为表 ' ' 中的标识列插入显式值”。    插入语句未显示指定ID。 报错:“仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表' '中的标识列指定显式值”。 from:http://www.cnblogs.com/wanghonghu/p/4093411.html

龙生   02 Feb 2016
View Details

C#实现动态生成Word

1. 一个控制台例子,实现动态生成Word。 首先,添加引用:COM->Microsoft Word 11.0 Object Library。

2. 介绍几篇牛人写的关于操作Word的文章 [分享]一段导出到word模版的代码 http://www.cnblogs.com/goody9807/archive/2005/08/25/222526.html 再谈word2003编程 http://www.cnblogs.com/Andmm/archive/2008/06/18/1224422.html 最近一直在做C#操作office方面的工作!总结一下!Word(二) http://www.cnblogs.com/wngwz/archive/2004/08/19/34678.html C#也能动态生成Word文档并填充数据 http://www.cnblogs.com/qyfan82/archive/2007/09/14/893293.html from:http://www.cnblogs.com/tianzhiliang/archive/2011/07/07/2099800.html

龙生   02 Feb 2016
View Details

C#也能动态生成Word文档并填充数据

引用http://blog.csdn.net/mengyao/archive/2007/09/13/1784079.aspx using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using Microsoft.Office.Interop.Word; namespace WindowsApplication4 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void button1_Click(object sender, EventArgs e)         {             CreateWordFile("c:\\dd.doc");         }         public string CreateWordFile(string CheckedInfo)        {             string message = "";             try             {                 Object Nothing = System.Reflection.Missing.Value;                 Directory.CreateDirectory("C:/CNSI");  //创建文件所在目录                 string name = "CNSI_" + DateTime.Now.ToLongDateString()+".doc";                 object filename = "C://CNSI//" + name;  //文件保存路径                 //创建Word文档                 Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();                 Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);                 //添加页眉                 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;                 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;                 WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]");                 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐                 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置                 WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距                 //移动焦点并换行                 object count = 14;                 object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;                  WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点                  WordApp.Selection.TypeParagraph();//插入段落                  //文档中创建表格                  Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref Nothing, ref Nothing);                  //设置表格样式                  newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleThickThinLargeGap;                  newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;                  newTable.Columns[1].Width = 100f;                  newTable.Columns[2].Width = 220f;                  newTable.Columns[3].Width = 105f;                  //填充表格内容                  newTable.Cell(1, 1).Range.Text = "产品详细信息表";                  newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体                  //合并单元格                  newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));                  WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中                  WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中                                           //填充表格内容                  newTable.Cell(2, 1).Range.Text = "产品基本信息";                  newTable.Cell(2, 1).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorDarkBlue;//设置单元格内字体颜色                  //合并单元格                  newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));                  WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;                   //填充表格内容                   newTable.Cell(3, 1).Range.Text = "品牌名称:";                   newTable.Cell(3, 2).Range.Text = "BrandName";                   //纵向合并单元格                   newTable.Cell(3, 3).Select();//选中一行                   object moveUnit = Microsoft.Office.Interop.Word.WdUnits.wdLine;                   object moveCount = 5;                   object moveExtend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;                    WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend);                    WordApp.Selection.Cells.Merge();                    //插入图片                    string FileName = @"c:\picture.jpg";//图片所在路径                    object LinkToFile = false;                    object SaveWithDocument = true;                    object Anchor = WordDoc.Application.Selection.Range;                    WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);                     WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度                     WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度                     //将图片设置为四周环绕型                     Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape(); […]

龙生   02 Feb 2016
View Details

C# Stream 和 byte[] 之间的转换

一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Image img = Image.FromStream(ms); ms.Close(); this.pictureBox1.Image 二. C#中byte[]与string的转换代码 1、System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); byte[] inputBytes =converter.GetBytes(inputString); string inputString = converter.GetString(inputBytes); 2、string inputString = System.Convert.ToBase64String(inputBytes); byte[] inputBytes = System.Convert.FromBase64String(inputString); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); 三. C# Stream 和 byte[] 之间的转换 /// 将 Stream 转成 byte[] public byte[] StreamToBytes(Stream stream) {     byte[] bytes = new byte[stream.Length];     stream.Read(bytes, 0, bytes.Length);     // 设置当前流的位置为流的开始     stream.Seek(0, SeekOrigin.Begin);     return bytes; } /// 将 byte[] 转成 Stream public Stream BytesToStream(byte[] bytes) {     Stream stream = new […]

龙生   02 Feb 2016
View Details