對(duì) Range 對(duì)象做 Copy 方法,要注意 Range 要連續(xù)的、成矩形選擇的。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到南譙網(wǎng)站設(shè)計(jì)與南譙網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋南譙地區(qū)。
例如像:A1:C5 可以復(fù)制,
例如像:A1:C5, A10:C15 就不能復(fù)制。
還要注意一點(diǎn):對(duì) Range 對(duì)象進(jìn)行操作的話,所在工作表先要激活。
someRange.Worksheet.Activate
如果還有問(wèn)題的話,可以把對(duì) Excel 操作的代碼提取到 Excel VBA 環(huán)境下調(diào)試好了再移植回去。
private void Save_Click(object sender, System.EventArgs e) { // Create a new save file dialog SaveFileDialog saveFileDialog1 = new SaveFileDialog(); // Sets the current file name filter string, which determines // the choices that appear in the "Save as file type" or // "Files of type" box in the dialog box. saveFileDialog1.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|SVG (*.svg)|*.svg|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif"; saveFileDialog1.FilterIndex = 2 ; saveFileDialog1.RestoreDirectory = true ; // Set image file format if(saveFileDialog1.ShowDialog() == DialogResult.OK) { ChartImageFormat format = ChartImageFormat.Bmp; if( saveFileDialog1.FileName.EndsWith( "bmp" ) ) { format = ChartImageFormat.Bmp; } else if( saveFileDialog1.FileName.EndsWith( "jpg" ) ) { format = ChartImageFormat.Jpeg; } else if( saveFileDialog1.FileName.EndsWith( "emf" ) ) { format = ChartImageFormat.Emf; } else if( saveFileDialog1.FileName.EndsWith( "gif" ) ) { format = ChartImageFormat.Gif; } else if( saveFileDialog1.FileName.EndsWith( "png" ) ) { format = ChartImageFormat.Png; } else if( saveFileDialog1.FileName.EndsWith( "tif" ) ) { format = ChartImageFormat.Tiff; } else if( saveFileDialog1.FileName.EndsWith( "svg" ) ) { format = ChartImageFormat.Svg; } // Save image Chart1.SaveImage( saveFileDialog1.FileName, format ); } }
說(shuō)實(shí)話你這個(gè)題目不是很明確
讓我有點(diǎn)不明白你想要的代碼是什么
那么我的理解就是
你現(xiàn)在有兩個(gè)表,表1,表2
你選中表1的某行,然后把選中的這行添加到表2去
如果是這樣的話那么做法就是
運(yùn)行環(huán)境 VB2008(.NET)
假設(shè)窗體名稱為Form1,你添加六個(gè)控件出來(lái)
表格控件DataGridView1,DataGridView2
按扭控件四個(gè)Button1,Button2,Button3,Button4
然后清空窗體里所有代碼使用我的代碼就行了
Imports System.Data.OleDb
Public Class Form1
Public LeafFileName As String = CurDir() "\Access.mdb" '這里是數(shù)據(jù)庫(kù)文件路徑和名稱,你自己改
Public LeafFormName As String = "projects" '這里是你要讀取這個(gè)數(shù)據(jù)庫(kù)內(nèi)的表的名稱
Public LeafPassWord As String = "leafsoftpassword" '這里是數(shù)據(jù)庫(kù)密碼,如果沒有密碼就隨便
Public LeafData1 As DataTable
Public LeafData2 As DataTable
Public LeafNewRow As DataRow '本次值得一提的是前兩次給你的代碼里都有這行,實(shí)際上這行在前兩次里是沒有用的,這行是添加行時(shí)需要的一個(gè)行的類,我忘記刪除掉這個(gè)了而已,恰好在這次需要使用了,讓你能更好地理解
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 = "轉(zhuǎn)移行"
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("讀取數(shù)據(jù)失敗,錯(cuò)誤號(hào)為:" Err.Number Chr(10) "錯(cuò)誤原因是:" 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).RowState DataRowState.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("找不到要?jiǎng)h除的行,可能該行已經(jīng)不存在.")
Catch LeafError As Exception
MsgBox("刪除數(shù)據(jù)失敗,錯(cuò)誤號(hào)為:" Err.Number Chr(10) "錯(cuò)誤原因是:" 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("保存數(shù)據(jù)失敗,錯(cuò)誤號(hào)為:" Err.Number Chr(10) "錯(cuò)誤原因是:" LeafError.Message)
Else
MsgBox("表內(nèi)數(shù)據(jù)并沒有更改.")
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("轉(zhuǎn)移行失敗,錯(cuò)誤號(hào)為:" Err.Number Chr(10) "錯(cuò)誤原因是:" LeafError.Message)
End Try
End Sub
End Class
哈哈我在出差,這幾天可能沒有空
如果過(guò)幾天還沒有結(jié)貼我再搞吧
Sub?Macro1()
Columns("A:A").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$A$5").AutoFilter?Field:=1,?Criteria1:="1"
Selection.Copy
Sheets("Sheet2").Select
Columns("A:A").Select
ActiveSheet.Paste
End?Sub
你錄制個(gè)宏就有代碼了 如上代碼所示
個(gè)人覺得:樓主所需要達(dá)到的,不應(yīng)該由。net來(lái)實(shí)現(xiàn)吧,以下是個(gè)人的一些學(xué)習(xí)筆記,或許可以幫助你,看看吧
SQL語(yǔ)句:select .....into....from
1、從B表中讀取數(shù)據(jù)插入到現(xiàn)有的A表:
insert into A select * from B where 條件;
2、新建一個(gè)與A表同樣結(jié)構(gòu)的表B,并把A表中滿足條件的數(shù)據(jù)寫入表B:
select * into B from A where 條件
3、根據(jù)一個(gè)表A的數(shù)據(jù),來(lái)更新表B的字段值(A,B表可以夸庫(kù))
update B
set B.字段1 =A.字段1,B.字段2=A.字段2
from A inner join B
on A.條件字段=B.條件字段
分類: 電腦/網(wǎng)絡(luò) 程序設(shè)計(jì) 其他編程語(yǔ)言
問(wèn)題描述:
在SQL數(shù)據(jù)庫(kù)里已有一個(gè)現(xiàn)成的空數(shù)據(jù)表(只有字段、沒有數(shù)據(jù)),請(qǐng)問(wèn)高手,怎樣在VB.NET中用SQL語(yǔ)句把該數(shù)據(jù)庫(kù)中的那個(gè)表復(fù)制一個(gè)到該數(shù)據(jù)庫(kù)(字段不變、數(shù)據(jù)為空)只是把數(shù)據(jù)表的名改了?
謝謝!謝謝!
解析:
select * into 新表 from 舊表
使用 SELECT INTO 插入行
SELECT INTO 語(yǔ)句創(chuàng)建一個(gè)新表,并用 SELECT 的結(jié)果集填充該表。新表的結(jié)構(gòu)由選擇列表中表達(dá)式的特性定義,例如:
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 可將幾個(gè)表或視圖中的數(shù)據(jù)組合成一個(gè)表。也可用于創(chuàng)建一個(gè)包含選自鏈接服務(wù)器的數(shù)據(jù)的新表。
新聞標(biāo)題:vb.net復(fù)制表 vb復(fù)制粘貼代碼
網(wǎng)站網(wǎng)址:http://aaarwkj.com/article30/hhhgso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、軟件開發(fā)、虛擬主機(jī)、企業(yè)建站、定制開發(fā)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)