| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1100 人关注过本帖
标题:[求助]一个简单的问题,复制数据库中的表
只看楼主 加入收藏
xuyanfeng66
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-1-20
收藏
 问题点数:0 回复次数:4 
[求助]一个简单的问题,复制数据库中的表
怎么实现ACCESS数据库中的表的复制啊?其中表的结构都是一样的,字段值分别为Tme(integer),Height(double),Area(double),想复制一个新表中,有两个文本框分别输入原来表的名字和新表的名字,叫Yuanbiao和Xinbiao吧,字段Tme复制后*10取整,该怎么写代码呢,谢谢各位好心人.
搜索更多相关主题的帖子: 数据库 Tme double 字段 
2007-01-21 13:22
xuyanfeng66
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-1-20
收藏
得分:0 

Dim SourceTableName As String = Yuanbiao.Text
Dim MyTableName As String = Xinbiao.Text

'创建新表
Dim myconn As New System.Data.OleDb.OleDbConnection
Dim strcnn As String
strcnn = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""newdata.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.J" & _
"et.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security in" & _
"fo=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=Fa" & _
"lse;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compac" & _
"t=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:G" & _
"lobal Bulk Transactions=1"
myconn.ConnectionString = strcnn
Dim MySql As String = "CREATE TABLE " + MyTableName + " (MyMt integer,Area double,Height double) "
Dim mycommand As New OleDb.OleDbCommand
mycommand.CommandText = MySql
Dim myada As New System.Data.OleDb.OleDbDataAdapter(MySql, myconn)
Dim Ds As New DataSet
If myconn.State = ConnectionState.Closed Then
myconn.Open()
End If
myada.Fill(Ds, "A")
myconn.Close()

'拷贝数据
Dim myconn1 As New System.Data.OleDb.OleDbConnection
Dim strcnn1 As String
strcnn1 = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""newdata.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.J" & _
"et.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security in" & _
"fo=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=Fa" & _
"lse;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compac" & _
"t=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:G" & _
"lobal Bulk Transactions=1"
myconn1.ConnectionString = strcnn1
Dim MySql1 As String = "select TABLE MyMt,Area,Height from " + SourceTableName + " "
Dim mycommand1 As New OleDb.OleDbCommand
mycommand1.CommandText = MySql1
Dim myada1 As New System.Data.OleDb.OleDbDataAdapter(MySql1, myconn)
Dim Ds1 As New DataSet
If myconn.State = ConnectionState.Closed Then
myconn.Open()
End If
myada1.Fill(Ds1, "B")
Dim ID, i As Integer
ID = Ds1.Tables(0).Rows.Count()
Dim temp(ID, 2)
For i = 0 To ID
temp(i, 0) = Int(Ds1.Tables.Item(0).Rows(i).Item(0) * 10 + 0.5)
temp(i, 1) = Ds1.Tables.Item(0).Rows(i).Item(1)
temp(i, 2) = Ds1.Tables.Item(0).Rows(i).Item(2)
Next i
myconn.Close()

'存储数据
Dim myconn2 As New System.Data.OleDb.OleDbConnection
Dim strcnn2 As String
strcnn1 = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""newdata.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.J" & _
"et.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security in" & _
"fo=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=Fa" & _
"lse;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compac" & _
"t=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:G" & _
"lobal Bulk Transactions=1"
myconn1.ConnectionString = strcnn1
If myconn.State = ConnectionState.Closed Then
myconn.Open()
End If
Dim MySql2 As String = "insert into " + MyTableName + " (MyMt,Area,Height) values (temp(ID, 0),temp(ID, 1),temp(ID, 2))"
Dim mycommand2 As New OleDb.OleDbCommand
mycommand2.CommandText = MySql2
Dim myada2 As New System.Data.OleDb.OleDbDataAdapter(MySql2, myconn)
myada2.Fill(Ds1, "B")
'mycommand2.ExecuteNonQuery()


这是我做的程序,前边的两个变量是文本框的NAME,运行是总出错, 到myada1.Fill(Ds1, "B")时,出现未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中,而且数据库中没有数据,只有空表

2007-01-21 14:54
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
Dim MySql1 As String = "select MyMt,Area,Height from " + SourceTableName + " "

飘过~~
2007-01-22 11:59
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 

其实这种贴应该发去数据库版~


2007-01-23 12:16
ncqingchuan
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2006-8-8
收藏
得分:0 
你用 select into 的SQL语句试一下嘛

[此贴子已经被作者于2007-4-2 13:45:02编辑过]


2007-04-02 13:44
快速回复:[求助]一个简单的问题,复制数据库中的表
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020144 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved