vb.net复制表 vb复制excel工作表

VB 。NET怎么把一个表的结构到复制到另一个表中个人觉得vb.net复制表:楼主所需要达到vb.net复制表的vb.net复制表,不应该由 。net来实现吧,以下是个人vb.net复制表的一些学习笔记,或许可以帮助你,看看吧
SQL语句:select .....into....from
1、从B表中读取数据插入到现有的A表:
insert into A select * from B where条件;
2、新建一个与A表同样结构的表B , 并把A表中满足条件的数据写入表B:
select * into B from A where 条件
3、根据一个表A的数据,来更新表B的字段值(A,B表可以夸库)
update B
set B.字段1 =A.字段1,B.字段2=A.字段2
from A inner join B
on A.条件字段=B.条件字段
vb.net将excel一个区域的内容复制到另外一个区域对 Range 对象做 Copy 方法vb.net复制表 , 要注意 Range 要连续的、成矩形选择的 。
例如像vb.net复制表:A1:C5 可以复制vb.net复制表,
例如像vb.net复制表:A1:C5, A10:C15 就不能复制 。
还要注意一点:对 Range 对象进行操作的话,所在工作表先要激活 。
someRange.Worksheet.Activate
如果还有问题的话 , 可以把对 Excel 操作的代码提取到 Excel VBA 环境下调试好vb.net复制表了再移植回去 。
VB.NET中如何用SQL语句建表(复制表)?谢谢了!分类:电脑/网络程序设计其他编程语言
问题描述:
在SQL数据库里已有一个现成的空数据表(只有字段、没有数据),请问高手,怎样在VB.NET中用SQL语句把该数据库中的那个表复制一个到该数据库(字段不变、数据为空)只是把数据表的名改了?
谢谢!谢谢!
解析:
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 可将几个表或视图中的数据组合成一个表 。也可用于创建一个包含选自链接服务器的数据的新表 。
复制某表的部分字段到新表 vb vb.net说实话你这个题目不是很明确
让我有点不明白你想要的代码是什么
那么我的理解就是
你现在有两个表,表1,表2
你选中表1的某行,然后把选中的这行添加到表2去
如果是这样的话那么做法就是
运行环境 VB2008(.NET)
假设窗体名称为Form1,你添加六个控件出来
表格控件DataGridView1,DataGridView2
按扭控件四个Button1,Button2,Button3,Button4
然后清空窗体里所有代码使用我的代码就行了
Imports System.Data.OleDb
Public Class Form1
Public LeafFileName As String = CurDir()"\Access.mdb" '这里是数据库文件路径和名称,你自己改
Public LeafFormName As String = "projects" '这里是你要读取这个数据库内的表的名称
Public LeafPassWord As String = "leafsoftpassword" '这里是数据库密码,如果没有密码就随便
Public LeafData1 As DataTable
Public LeafData2 As DataTable
Public LeafNewRow As DataRow '本次值得一提的是前两次给你的代码里都有这行,实际上这行在前两次里是没有用的,这行是添加行时需要的一个行的类,我忘记删除掉这个了而已,恰好在这次需要使用了,让你能更好地理解
Dim LeafOleDbConnection As OleDbConnection
Dim LeafOleDbCommand As OleDbCommand
Dim LeafOleDbDataAdapter As OleDbDataAdapter
Dim LeafCommandBuilder As OleDbCommandBuilder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "读取"
Button2.Text = "保存"
Button3.Text = "删除"
Button4.Text = "转移行"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim LeafITemp As Integer
LeafOleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="LeafFileName";""Jet OLEDB:Database Password='"LeafPassWord"';")
LeafOleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM "LeafFormName, LeafOleDbConnection)
LeafData1 = New DataTable
LeafData2 = New DataTable
LeafOleDbDataAdapter.Fill(LeafData1)
DataGridView1.DataSource = LeafData1
For LeafITemp = 0 To LeafData1.Columns.Count - 1
LeafData2.Columns.Add(LeafData1.Columns(LeafITemp).ColumnName)
Next
DataGridView2.DataSource = LeafData2
Catch LeafError As Exception
MsgBox("读取数据失败,错误号为:"Err.NumberChr(10)"错误原因是:"LeafError.Message)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Save()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim LeafITemp As Integer
Try
For LeafITemp = 0 To LeafData1.Rows.Count - 1
If LeafData1.Rows(LeafITemp).RowStateDataRowState.Deleted Then
If LeafData1.Rows(LeafITemp).Item(0) = DataGridView1(0, DataGridView1.CurrentRow.Index).Value Then
LeafData1.Rows(LeafITemp).Delete()
Save()
Exit Sub
End If
End If
Next
MsgBox("找不到要删除的行,可能该行已经不存在.")
【vb.net复制表 vb复制excel工作表】Catch LeafError As Exception
MsgBox("删除数据失败,错误号为:"Err.NumberChr(10)"错误原因是:"LeafError.Message)
End Try
End Sub
Sub Save()
LeafOleDbCommand = New OleDbCommand("SELECT * FROM "LeafFormName, LeafOleDbConnection)
LeafOleDbDataAdapter = New OleDbDataAdapter
LeafCommandBuilder = New OleDbCommandBuilder(LeafOleDbDataAdapter)
LeafOleDbCommand.CommandType = CommandType.Text
LeafOleDbDataAdapter.SelectCommand = LeafOleDbCommand
Try
LeafOleDbDataAdapter.Update(LeafData1.GetChanges)
LeafData1.AcceptChanges()
Catch LeafError As Exception
If Microsoft.VisualBasic.Left(LeafError.Message, 5)"值不能为空" Then
MsgBox("保存数据失败,错误号为:"Err.NumberChr(10)"错误原因是:"LeafError.Message)
Else
MsgBox("表内数据并没有更改.")
End If
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
Dim LeafITemp As Integer
LeafNewRow = LeafData2.NewRow
For LeafITemp = 0 To LeafData2.Columns.Count - 1
LeafNewRow.Item(LeafITemp) = DataGridView1(LeafITemp, DataGridView1.CurrentRow.Index).Value
Next
LeafData2.Rows.Add(LeafNewRow)
Catch LeafError As Exception
MsgBox("转移行失败,错误号为:"Err.NumberChr(10)"错误原因是:"LeafError.Message)
End Try
End Sub
End Class
哈哈我在出差,这几天可能没有空
如果过几天还没有结贴我再搞吧
vb.net复制表的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vb复制excel工作表、vb.net复制表的信息别忘了在本站进行查找喔 。

    推荐阅读