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')
Insert into Table1 values('李','asds',null)
GO
--3.SELECT INTO FROM语句创建表Table2并复制数据
select a,c INTO Table2 from Table1
GO
--4.显示更新后的结果
select * from Table2
GO
--5.删除测试表
drop TABLE Table1
drop TABLE Table2
今天看了一篇文章,是介绍JQ中的排序问题。用到的是它的一个插件tablesorter.js,更丰富的话还会用到jquery-latest.js以及jquery.tablesorter.pager.js。
用到的语句是这样的:
- $(document).ready(function() {
- $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );
- }
- )
有点不太明白,查了下sortList的参数,但是没有任何结果。后来在一位大哥的指点下找到了答案:
排序列表[0,0][1,0],按第一列,第二列进行升序排序,[列索引,排序方向] 0 asc(升序) 1 desc(降序)。
还有一些其他的参数:
第一部分
禁止第二列.每三列进行排序
- $(document).ready(function(){
- $("myTable").tablesorter({
- // pass the headers argument and assing a object
- headers: {
- // assign the secound column (we start counting zero)
- 1: {
- // disable it by setting the property sorter to false
- sorter: false},
- // assign the third column (we start counting zero)
- 2: {
- // disable it by setting the property sorter to false
- sorter: false}
- }
- });
- });
使用TH更像一个按钮
- $(document).ready(function(){
- $("#myTable").tableSorter(
- {cancelSelection:true}
- );
- });
强制某列排序后不能动,其它列根据该列进行排序
- $(document).ready(function(){
- // call the tablesorter plugin\
- $("myTable").tablesorter({
- // set forced sort on the fourth column and i decending order.
- sortForce: [[0,0]]}
- );
- });
按键的更换
- $(document).ready(function(){
- // call the tablesorter plugin
- $("table").tablesorter({
- // change the multi sort key from the default shift to alt button
- sortMultiSortKey: ‘altKey’
- });
- });
顺便查到一些ui的其他插件:
ui.draggable.ext.js
用法:文件载入后,可以拖拽class = “block”的层
- $(document).ready(function(){
- $(”.block”).draggable();
- });
draggable(options)可以跟很多选项
选项说明:http://docs.jquery.com/UI/Draggables/draggable#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/draggable.html
Droppables:
所需要文件,drag drop
ui.mouse.js
ui.draggable.js
ui.draggable.ext.js
ui.droppable.js
ui.droppable.ext.js
用法:
- $(document).ready(function(){
- $(”.block”).draggable({helper: ‘clone’});
- $(”.drop”).droppable({
- accept: “.block”,
- activeClass: ‘droppable-active’,
- hoverClass: ‘droppable-hover’,
- drop: function(ev, ui) {
- $(this).append(”<br>Dropped!”);
- }
- });
- });
选项说明:http://docs.jquery.com/UI/Droppables/droppable#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/droppable.html
Sortables排序:
所需要的文件
jquery.dimensions.js
ui.mouse.js
ui.draggable.js
ui.droppable.js
ui.sortable.js
用法:
- $(document).ready(function(){
- $(”#myList”).sortable({});
- });
dimensions文档http://jquery.com/plugins/project/dimensions
选项说明:http://docs.jquery.com/UI/Sortables/sortable#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.sortable.html
Selectables 选择:
所需要的文件
jquery.dimensions.js
ui.mouse.js
ui.draggable.js
ui.droppable.js
ui.selectable.js
用法:
- $(document).ready(function(){
- $(”#myList”).selectable();
- });
选项说明:http://docs.jquery.com/UI/Selectables/selectable#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/selectable.html
Resizables改变大小:
所需要的文件 ,此例子需要几个css文件
jquery.dimensions.js
ui.mouse.js
ui.resizable.js
用法:
- $(document).ready(function(){
- $(”#example”).resizable();
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/UI/Resizables/resizable#options
选项实例:http://dev.jquery.com/view/trunk … s/ui.resizable.html
第二部分:互动效果:
Accordion 折叠菜单:
所需要的文件:
ui.accordion.js
jquery.dimensions.js
用法:
- $(document).ready(function(){
- $(”#example”).accordion();
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/UI/Accordion/accordion#options
选项实例:http://dev.jquery.com/view/trunk/plugins/accordion/?p=1.1.1
dialogs 对话框:
所需要的文件:
jquery.dimensions.js
ui.dialog.js
ui.resizable.js
ui.mouse.js
ui.draggable.js
用法:
- $(document).ready(function(){
- $(”#example”).dialog();
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/UI/Dialog/dialog#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/dialog.html
sliders 滑动条:
所需要的文件
jquery.dimensions.js
ui.mouse.js
ui.slider.js
用法:
- $(document).ready(function(){
- $(”#example”).slider();
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/UI/Slider/slider#options
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.slider.html
Tablesorter表格排序:
所需要的文件
ui.tablesorter.js
用法:
- $(document).ready(function(){
- $(”#example”).tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/Plugins/Tablesorter/tablesorter#options
选项实例:http://tablesorter.com/docs/#Demo
tabs页签(对IE支持不是很好):
所需要的文件
ui.tabs.js
用法:
- $(document).ready(function(){
- $(”#example > ul”).tabs();
- });
CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css
选项说明:http://docs.jquery.com/UI/Tabs/tabs#initialoptions
选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/tabs.html
tabs ext http://stilbuero.de/jquery/tabs_3/rotate.html
第三部分:效果:
Shadow 阴影
实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.shadow.html
Magnifier 放大
实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.magnifier.html
System.IO.MemoryStream Ms = new MemoryStream();
this.pcbEquipment.Image.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] img = new byte[Ms.Length];
Ms.Position = 0;
Ms.Read(img, 0, Convert.ToInt32(Ms.Length));
Ms.Close();
代码public void DoUpload(string fileName, byte[] context, bool append)
{
//上传目录
string folder = System.Web.Hosting.HostingEnvironment.MapPath("~/upload");
if (!System.IO.Directory.Exists(folder))
{
//如果上传目录不存在则新建一个
System.IO.Directory.CreateDirectory(folder);
}
//文件读写模式
FileMode m = FileMode.Create;
if (append)
{
//如果参数为true则表示续传,以追加模式操作文件
m = FileMode.Append;
}
//写文件操作
using (FileStream fs = new FileStream(folder + @"\" + fileName, m, FileAccess.Write))
{
fs.Write(context, 0, context.Length);
}
return;
}
void uploader_DoUploadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error == null)
{
//上一个包上传成功
uploadfile file = e.UserState as uploadfile;
//修改已上传大小(显示作用)
file.sent += file.context[0].Length / 1000;
//删除已上传内容
file.context.RemoveAt(0);
//如果上传内容是空,完成操作
if (file.context.Count == 0)
{
bt.Content = "upload";
MessageBox.Show("upload OK");
}
else
{
//如果上传内容不是空,则继续剩余下一段内容上传
(sender as ServiceReference1.uploadServiceClient).DoUploadAsync(file.name, file.context[0], true, file);
//显示进度
bt.Content = file.sent.ToString() + "/" + file.size.ToString();
}
}
}
}
public class uploadfile
{
//文件名
public string name { get; set; }
//文件大小
public double size { get; set; }
//已上传
public double sent { get; set; }
//上传内容
public List<byte[]> context { get; set; }
}
//点击事件
void bt_Click(object sender, RoutedEventArgs e)
{
//选择本地文件对话框
OpenFileDialog d = new OpenFileDialog();
//文件过滤
d.Filter = "(*.*)|*.*";
//只能选单个文件
d.Multiselect = false;
//选择完成
if (d.ShowDialog() == true)
{
//文件信消
FileInfo f = d.File;
//新实例化一个文件从uploadfile类
uploadfile file = new uploadfile();
//文件名
file.name = f.Name;
//文件流内容
Stream s = f.OpenRead();
//文件大小(/1000是为了方便查看,成为k为单位)
file.size = s.Length / 1000;
//实例file的内容
file.context = new List<byte[]>();
//这里读取指定大小的文件流内容到file.context准备上传
int b;
while (s.Position > -1 && s.Position < s.Length)
{
if (s.Length - s.Position >= 300)
{
b = 3000;
}
else
{
b = (int)(s.Length - s.Position);
}
byte[] filebyte = new byte[b];
s.Read(filebyte, 0, b);
file.context.Add(filebyte);
}
s.Close();
//实例化wcf客户端
ServiceReference1.uploadServiceClient uploader = new uploadFile.ServiceReference1.uploadServiceClient();
//注册DoUpload完成事件
uploader.DoUploadCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(uploader_DoUploadCompleted);
//开始第一个包的上传
uploader.DoUploadAsync(file.name, file.context[0], false, file);
}
}
