Vb newb需要数据导入/导出方面的帮助 [英] Vb newb needs help on data import/export

查看:75
本文介绍了Vb newb需要数据导入/导出方面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


im完全是vb.net的新手,我被分配做一个简单的

软件,只需从中选择um db在MS访问数据库中

并插入到SQL Server数据库中。结构表格是完全相同的,所以没有必要进行数据对话。


我的想法是用我的结果填充数据表

oledbdataadapter然后使用该数据集更新我的

sqldataadapterm,但是我无法找到指定连接的方式

字符串到我的sqldataadapter到我的SQL数据库。可能这不是实现这个目标的最好方法,但是从这个链接中得到了这个想法:
http://www.dotnet247.com/247referenc...40/203742.aspx 这个

伙计们我试图做同样的事情。


我的代码看起来像这样。


Dim strConn =" Provider = Microsoft。 Jet.OleDb.4.0;数据源=" &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.Update(dtAccessData)


也许有些消息如何把这段代码运行起来或其他一些消息如何实现这个目标其他方式。


非常感谢任何帮助


提前致谢


Joao

解决方案

9月28日上午7:40,joaotsetsemo ... @ gmail.com写道:


大家好,


我是vb.net的新手,我被分配做一个简单的

软件只需从MS访问数据库中选择um db

并插入进入SQL服务器数据库。结构表格是完全相同的,所以没有必要进行数据对话。


我的想法是用我的结果填充数据表

oledbdataadapter然后使用该数据集更新我的

sqldataadapterm,但是我无法找到指定连接的方式

字符串到我的sqldataadapter到我的SQL数据库。可能这不是实现这个目标的最好方法,但是从这个链接中得到了这个想法: http://www.dotnet247.com/247referenc...3742.aspxwhere 这个

家伙试图做同样的事情我想要的东西。


我的代码看起来像这样。

Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data源= QUOT; &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.Update(dtAccessData)


也许有些消息如何把这段代码运行起来或其他一些消息如何实现这个目标其他方式。


非常感谢任何帮助


提前致谢


Joao



你已经有了正确的想法,但是你需要为sqlAdapter单独设置一个

dbConnection。


Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data Source =" &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

cnConn.Close()

accessAdapter.Dispose()

cnConn.Dispose()


Dim sqlConnString as String ="你的SQL连接字符串在这里

Dim dbConn as new SqlClient.SqlConnection(sqlConnString)

Dim dbCmd as new SqlClient.SqlCommand(" INSERT SQL STATEMENT",dbConn)

Dim sqlAdapter作为新的SqlDataAdapter(dbCmd)

sqlAdapter.Update(dtAccessData)

dbConn.Close()

sqlAdapter.Dispose()

dbCmd.Dispose()

dbConn.Dispose()

查看额外的代码行,它是一个向下和脏的版本,

并且可能更清洁,但应该让你去。永远记得

关闭你的连接并处理实施

iDisposable的对象。


On 9月28日上午9:01,Charlie Brown< cbr ... @ duclaw.comwrote:


9月28日上午7:40,joaotsetsemo ...... @ gmail.com写道:


大家好,


im completly new to vb .net和我被分配做一个简单的

软件,只需从MS访问数据库中选择um db

并插入SQL服务器数据库。结构表与

完全相同,因此不需要数据对话。


我的想法是用我的

oledbdataadapter的结果填充数据表,然后使用该数据集更新我的数据

sqldataadapterm,但是我无法找到指定连接的方式

字符串到我的sqldataadapter到我的SQL数据库。可能这不是实现这个目标的最好方法,但是从这个链接中得到了这个想法: http://www.dotnet247.com/247referenc....aspxwherethis

伙计们试图做同样的事情我想。


我的代码如下所示。


Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data Source =" &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.Update(dtAccessData)


或许有些消息如何使这段代码工作或其他一些

消化如何通过任何其他方式实现这一目标。


任何帮助都非常感谢


在此先感谢


Joao



你已经有了正确的想法,但你需要另外一个

用于sqlAdapter的dbConnection。

Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data Source =" &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

cnConn.Close()

accessAdapter.Dispose()

cnConn.Dispose()


Dim sqlConnString as String ="你的SQL连接字符串在这里

Dim dbConn as new SqlClient.SqlConnection(sqlConnString)

Dim dbCmd as new SqlClient.SqlCommand(" INSERT SQL STATEMENT",dbConn)

Dim sqlAdapter作为新的SqlDataAdapter(dbCmd)

sqlAdapter.Update(dtAccessData)

dbConn.Close()

sqlAdapter.Dispose()

dbCmd.Dispose()

dbConn.Dispose()



请记住首先打开这些连接对象....: - )


查看c的附加行颂歌,它是一个羽绒和肮脏的版本,

,可能更干净,但应该让你去。永远记得

关闭你的连接并处理实现

iDisposable的对象。



我还建议使用try ... finally结构将方法包装在Using块或

中以确保Db对象得到

处置。另外,IIRC,如果你是

调用Dispose,则不需要关闭连接。


谢谢,


Seth Rowe


9月28日下午2:25,rowe_newsgroups< rowe_em ... @ yahoo.comwrote:


9月28日上午9:01,Charlie Brown< cbr ... @ duclaw.comwrote:



On 9月28日上午7:40,joaotsetsemo ... @ gmail.com写道:


大家好,


im completly new to vb.net我被分配做一个简单的

软件只需从MS访问数据库中的um db中选择

并插入到SQL Server数据库中。结构表与

完全相同,因此不需要数据对话。


我的想法是用我的结果填充数据表

oledbdataadapter然后使用该数据集来更新我的
sqldataadapterm,但是我无法找到指定连接的方式

字符串到我的sqldataadapter到我的SQL数据库。可能这不是实现这个目标的最好方法,但是从这个链接中得到了这个想法: http://www.dotnet247.com/247referenc....aspxwherethis

伙计们试图做同样的事情我想。


我的代码如下所示。


Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data Source = " &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.Update(dtAccessData)


也许有些消息如何把这段代码工作或其他一些

sugestion如何通过任何其他方式实现这一目标。


非常感谢任何帮助

< blockquote class =post_quotes>


先谢谢


Joao


你已经有了正确的想法,但你需要单独制作

sqlAdapter的dbConnection。


Dim strConn =" Provider = Microsoft.Jet.OleDb.4.0; Data Source =" &

Application.StartupPath& " \ sapo.mdb"

Dim cnConn As New OleDbConnection(strConn)

Dim accessAdapter As New OleDbDataAdapter(" select * from

交易",cnConn)

Dim dtAccessData As New DataTable

accessAdapter.Fill(dtAccessData)

cnConn.Close()

accessAdapter.Dispose()

cnConn.Dispose()


Dim sqlConnString as String =" YOUR SQL CONNECTION STRING HERE"

Dim dbConn as new SqlClient.SqlConnection(sqlConnString)

Dim dbCmd as new SqlClient.SqlCommand(" INSERT SQL STATEMENT",dbConn)

Dim sqlAdapter As New SqlDataAdapter(dbCmd)

sqlAdapter.Update(dtAccessData)

dbConn.Close()

sqlAdapter .Dispose()

dbCmd.Dispose()

dbConn.Dispose()



记得打开那些连接对象首先...... :-)


查看额外的代码行,它是一个向下和脏的版本,

并且可能更干净但是应该让你去。永远记得

关闭你的连接并处理实现

iDisposable的对象。



我还建议使用try ... finally结构将方法包装在Using块或

中以确保Db对象得到

处置。另外,IIRC,如果你是

调用Dispose,则不需要关闭连接。


谢谢,


Seth Rowe-隐藏引用的文字 -


- 显示引用的文字 -



感谢您的回复,我会尽力尝试仍然是

想念我。


如果在第一段代码中我分配了所有结果select

*来自交易对于一个数据表,为什么我需要一个插入,以及在第二段代码中将如何插入?b $ b?我不能只是

选择数据表并将其大致插入SQL服务器数据库

使用sqldataadapter.update?


Hello everyone,

im completly new to vb.net and I was assigned to do a simple piece of
software that just had to select from um db in a MS access data base
and insert into a SQL server Database. The structure tables are
exactly the same so there''s no need in data conversation.

My idea was to fill a datatable with the results from my
oledbdataadapter and then use that dataset to update on my
sqldataadapterm, however I cant find the way to specify the connection
string to my sqldataadapter to my SQL database. Probably this is not
the best way to achieve this but got this idea from this link:
http://www.dotnet247.com/247referenc...40/203742.aspx where this
guys is trying to do exactly the same thing I want.

My code looks like this.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
Dim sqlAdapter As New SqlDataAdapter
sqlAdapter.Update(dtAccessData)

Perhaps some sugestion how to put this code working or some other
sugestion how to achieve this goal by any other way.

Any help is highly appreciated

Thanks in advance

Joao

解决方案

On Sep 28, 7:40 am, joaotsetsemo...@gmail.com wrote:

Hello everyone,

im completly new to vb.net and I was assigned to do a simple piece of
software that just had to select from um db in a MS access data base
and insert into a SQL server Database. The structure tables are
exactly the same so there''s no need in data conversation.

My idea was to fill a datatable with the results from my
oledbdataadapter and then use that dataset to update on my
sqldataadapterm, however I cant find the way to specify the connection
string to my sqldataadapter to my SQL database. Probably this is not
the best way to achieve this but got this idea from this link:http://www.dotnet247.com/247referenc...3742.aspxwhere this
guys is trying to do exactly the same thing I want.

My code looks like this.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
Dim sqlAdapter As New SqlDataAdapter
sqlAdapter.Update(dtAccessData)

Perhaps some sugestion how to put this code working or some other
sugestion how to achieve this goal by any other way.

Any help is highly appreciated

Thanks in advance

Joao

You have the correct idea already, but you need to make a separate
dbConnection for the sqlAdapter.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
cnConn.Close()
accessAdapter.Dispose()
cnConn.Dispose()

Dim sqlConnString as String = "YOUR SQL CONNECTION STRING HERE"
Dim dbConn as New SqlClient.SqlConnection(sqlConnString)
Dim dbCmd as New SqlClient.SqlCommand("INSERT SQL STATEMENT", dbConn)
Dim sqlAdapter As New SqlDataAdapter(dbCmd)
sqlAdapter.Update(dtAccessData)
dbConn.Close()
sqlAdapter.Dispose()
dbCmd.Dispose()
dbConn.Dispose()

Look at the additional lines of code, its a down and dirty version,
and could be cleaner but should get you going. Always remember to
close your connections and dispose of objects that implement
iDisposable.


On Sep 28, 9:01 am, Charlie Brown <cbr...@duclaw.comwrote:

On Sep 28, 7:40 am, joaotsetsemo...@gmail.com wrote:

Hello everyone,

im completly new to vb.net and I was assigned to do a simple piece of
software that just had to select from um db in a MS access data base
and insert into a SQL server Database. The structure tables are
exactly the same so there''s no need in data conversation.

My idea was to fill a datatable with the results from my
oledbdataadapter and then use that dataset to update on my
sqldataadapterm, however I cant find the way to specify the connection
string to my sqldataadapter to my SQL database. Probably this is not
the best way to achieve this but got this idea from this link:http://www.dotnet247.com/247referenc....aspxwherethis
guys is trying to do exactly the same thing I want.

My code looks like this.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
Dim sqlAdapter As New SqlDataAdapter
sqlAdapter.Update(dtAccessData)

Perhaps some sugestion how to put this code working or some other
sugestion how to achieve this goal by any other way.

Any help is highly appreciated

Thanks in advance

Joao


You have the correct idea already, but you need to make a separate
dbConnection for the sqlAdapter.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
cnConn.Close()
accessAdapter.Dispose()
cnConn.Dispose()

Dim sqlConnString as String = "YOUR SQL CONNECTION STRING HERE"
Dim dbConn as New SqlClient.SqlConnection(sqlConnString)
Dim dbCmd as New SqlClient.SqlCommand("INSERT SQL STATEMENT", dbConn)
Dim sqlAdapter As New SqlDataAdapter(dbCmd)
sqlAdapter.Update(dtAccessData)
dbConn.Close()
sqlAdapter.Dispose()
dbCmd.Dispose()
dbConn.Dispose()

Remember to open those connection objects first.... :-)

Look at the additional lines of code, its a down and dirty version,
and could be cleaner but should get you going. Always remember to
close your connections and dispose of objects that implement
iDisposable.

I would also recommend either wrapping the methods in a Using block or
using try...finally structure to make sure the Db objects get
disposed. Also, IIRC, closing the connection is unnecessary if you are
calling Dispose.

Thanks,

Seth Rowe


On Sep 28, 2:25 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:

On Sep 28, 9:01 am, Charlie Brown <cbr...@duclaw.comwrote:


On Sep 28, 7:40 am, joaotsetsemo...@gmail.com wrote:

Hello everyone,

im completly new to vb.net and I was assigned to do a simple piece of
software that just had to select from um db in a MS access data base
and insert into a SQL server Database. The structure tables are
exactly the same so there''s no need in data conversation.

My idea was to fill a datatable with the results from my
oledbdataadapter and then use that dataset to update on my
sqldataadapterm, however I cant find the way to specify the connection
string to my sqldataadapter to my SQL database. Probably this is not
the best way to achieve this but got this idea from this link:http://www.dotnet247.com/247referenc....aspxwherethis
guys is trying to do exactly the same thing I want.

My code looks like this.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
Dim sqlAdapter As New SqlDataAdapter
sqlAdapter.Update(dtAccessData)

Perhaps some sugestion how to put this code working or some other
sugestion how to achieve this goal by any other way.

Any help is highly appreciated

Thanks in advance

Joao

You have the correct idea already, but you need to make a separate
dbConnection for the sqlAdapter.

Dim strConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &
Application.StartupPath & "\sapo.mdb"
Dim cnConn As New OleDbConnection(strConn)
Dim accessAdapter As New OleDbDataAdapter("select * from
transactions", cnConn)
Dim dtAccessData As New DataTable
accessAdapter.Fill(dtAccessData)
cnConn.Close()
accessAdapter.Dispose()
cnConn.Dispose()

Dim sqlConnString as String = "YOUR SQL CONNECTION STRING HERE"
Dim dbConn as New SqlClient.SqlConnection(sqlConnString)
Dim dbCmd as New SqlClient.SqlCommand("INSERT SQL STATEMENT", dbConn)
Dim sqlAdapter As New SqlDataAdapter(dbCmd)
sqlAdapter.Update(dtAccessData)
dbConn.Close()
sqlAdapter.Dispose()
dbCmd.Dispose()
dbConn.Dispose()


Remember to open those connection objects first.... :-)

Look at the additional lines of code, its a down and dirty version,
and could be cleaner but should get you going. Always remember to
close your connections and dispose of objects that implement
iDisposable.


I would also recommend either wrapping the methods in a Using block or
using try...finally structure to make sure the Db objects get
disposed. Also, IIRC, closing the connection is unnecessary if you are
calling Dispose.

Thanks,

Seth Rowe- Hide quoted text -

- Show quoted text -

Thanks for your replies, I will try that however something is still
missing me.

If in the first piece of code I assign all the results of the "select
* from transactions" to a datatable, why do I need an insert and how
is gonna be that insert, in the second piece of code? Can''t I just
pick the datatable and roughly insert it in the SQL server data base
using the sqldataadapter.update?


这篇关于Vb newb需要数据导入/导出方面的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆