十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
select * into 新表 from 旧表
成都创新互联公司专业为企业提供开平网站建设、开平做网站、开平网站设计、开平网站制作等企业网站建设、网页设计与制作、开平企业网站模板建站服务,十多年开平做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
使用 SELECT INTO 插入行
SELECT INTO 语句创建一个新表,并用 SELECT 的结果集填充该表。新表的结构由选择列表中表达式的特性定义,例如:
SELECT Shippers.*, Link.Address, Link.City,
Link.Region, Link.PostalCode
INTO NewShippers
FROM Shippers
JOIN LinkServer.DB.dbo.Shippers AS Link
ON (Shippers.ShipperID = Link.ShipperID)
SELECT INTO 可将几个表或视图中的数据组合成一个表。也可用于创建一个包含选自链接服务器的数据的新表。
以下是我以前百度找的资料 希望对你有用 你读取DataGridView到DataGrid然后直接调用函数即可
Public Function ExportXLsD(ByVal datagrid As DataGrid) ', ByVal Title As String)
'Dim Mytable As New DataTable
'Mytable = CType(datagrid.DataSource, DataTable)
If mytable Is Nothing Then
MessageBox.Show("没有记录不能导出数据", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Function
End If
If mytable.Rows.Count 0 Then
Dim MyFileName As String
Dim FileName As String
With SaveFileDialog1
.AddExtension = True '如果用户忘记添加扩展名,将自动家上
.DefaultExt = "xls" '默认扩展名
.Filter = "Excel文件(*.xls)|*.xls"
.Title = "文件保存到"
If .ShowDialog = DialogResult.OK Then
FileName = .FileName
End If
End With
MyFileName = Microsoft.VisualBasic.Right(FileName, 4)
If MyFileName = "" Then
Exit Function
End If
If MyFileName = ".xls" Or MyFileName = ".XLS" Then
Dim FS As FileStream = New FileStream(FileName, FileMode.Create)
Dim sw As StreamWriter = New StreamWriter(FS, System.Text.Encoding.Default)
sw.WriteLine(vbTab FileName vbTab Date.Now)
Dim i, j As Integer
Dim str As String = ""
For i = 0 To mytable.Columns.Count - 1
str = mytable.Columns(i).Caption
sw.Write(str vbTab)
Next
sw.Write(vbCrLf)
For j = 0 To mytable.Rows.Count - 1
For i = 0 To mytable.Columns.Count - 1
Dim strColName, strRow As String
strRow = IIf(mytable.Rows(j).Item(i) Is DBNull.Value, "", mytable.Rows(j).Item(i))
sw.Write(strRow vbTab)
Next
sw.Write(vbLf)
Next
sw.Close()
FS.Close()
MessageBox.Show("数据导出成功!", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Exit Function
End If
Else
MessageBox.Show("没有记录不能导出数据", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Function
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Dim saveExcel As SaveFileDialog
saveExcel = New SaveFileDialog
saveExcel.Filter = "Excel文件(.xls)|*.xls"
Dim filename As String
If saveExcel.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
filename = saveExcel.FileName
Dim excel As Excel.Application
excel = New Excel.Application
excel.DisplayAlerts = False
excel.Workbooks.Add(True)
excel.Visible = False
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
excel.Cells(1, i + 1) = DataGridView1.Columns(i).HeaderText
Next
'设置标题
Dim j As Integer
For i = 0 To DataGridView1.Rows.Count - 1 '填充数据
For j = 0 To DataGridView1.Columns.Count - 1
excel.Cells(i + 2, j + 1) = DataGridView1(j, i).Value
Next
Next
excel.Workbooks(1).SaveCopyAs(filename) '保存
Me.Close()
End Sub
这个我是这么实现的.要用到
Excel.Application
Set xlapp = CreateObject("Excel.Application") '激活EXCEL
xlapp.Visible = True '让EXCEL可见
Set xlbook = xlapp.Workbooks.Open(App.Path + "个人简历.xlt")
'打开工作簿,strDestination为一个EXCEL报表文件
Set xlsheet = xlbook.Worksheets(1) '设定工作表
这个有点像是vb6的、vb.net也有相应的方法的.总之是
excel.application 用到这个就可以了.必要的话导入excel的dll文件.
这样你就发现、可以用vb.net来对excel来操作.你可以查下微软的msdn、有具体的属性方法.
如:
Dim ef As New Excel.Application
Dim es As New Excel.Worksheet
Dim er As Excel.Range
ef.Workbooks.Add()
es = ef.Worksheets("sheet1")
es.Activate()
er = es.Range("a1:C1")
er.Select()
er.Merge()
er.Value = "gordon1117"
ef.Visible = True 目前应用了三个对象:application,worksheet和range,三者的关系应该清晰,做到这点就能从基本开始做了:)格式设置都在range对象,只不过在设置对齐属性上是verticalalignment和horizon
range 用来定位、
然后你可以循环把数据输出到指定了格式的excel文件里了吧、其实连格式都是可以程序控制的好好学下吧.
可以参考一下这篇文章
直接打开EXCEL用CTRL+F ,可以直接定位到符合条件的数据;或用指定条件筛选
"INSERT INTO 订单信息(订单状态,接单种类) select 状态编号,接单编号 from (select 状态编号 from 订单状态 where 订单状态='" ComboBox1.Text "') A,(select 接单编号 from 接单种类 where 接单种类='" ComboBox2.Text "') B"
这样试一下。