HLP:打开Access数据库问题 [英] HLP: Opening Access DB issues

查看:63
本文介绍了HLP:打开Access数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.net 2003; MS Access db; Netframe 1.1

我为我上一个工作地点写了一个Windows应用程序,打开了

修改了几个MS Access数据库文件。我在家里完成了大部分的编程工作

在Drive" C"上。我使用拖放数据项来创建连接,

DataSet和DataAdapters。

Access文件位于驱动器P上。和S在工作中,所以我在工作PC上安装了VB.net

所以我可以在连接图标中更改驱动器。


现在我不再工作了在那个地方,他们希望我做一些改变。

当然我不能因为我的系统上没有驱动器P或S.所以我正在尝试

摆脱数据图标并使用

代码进行连接,数据集和适配器。当然,我得到了各种各样的错误。


所以我正在做一个测试应用程序来查找/修复我的项目。马上,我甚至无法建立与数据库的正确连接。以下是我正在使用的代码。


我在FILL行得到一个错误(未处理的异常,其中Value不能是$ / b $ b null但是如果我使用DATA图标,访问文件就会打开。


并且...如果我将填充行更改为:

daShenData.FillSchema (dsShenData,SchemaType.Source," SHENHrsTable")

....错误然后显示ConnectionString属性尚未初始化为



**************代码************************** *********************

Imports System.IO

Imports System.Data.OleDb

''连接String1到SHENTSdata.mdb

Dim connString1 As String =" Provider = Microsoft.Jet.OLEDB.4.0; Data

Source = TSdbPath& SHENTSdata.mdb"


Dim OleDbConnection1 As OleDbConnection = New OleDbConnection


''数据适配器1

Dim strSelect1 As String

strSelect1 =" SELECT Bill_Code,Dispersmts,Fri_Hrs,Job_Descrn,

Job_Number,Mileage," &安培; _

Mon_Hrs,Period_End_Date,PO_Order,Sat_Hrs,Sun_Hrs,

Thr_Hrs,Tue_Hrs," &安培; _

" Wed_Hrs,Work_Descrn FROM SHENHrsTable"

Dim daShenData As New OleDbDataAdapter(strSelect1,OleDbConnection1)


''数据集1

Dim dsShenData作为新数据集


''填充数据集1

daShenData.Fill(dsShenData.Tables(" SHENHrsTable" ;))

''''''daShenData.FillSchema(dsShenData,SchemaType.Source," SHENHrsTable")

********** **************************************** ********** ********


问题#1:

如何解决No Null值问题(为什么它仍然这样做)?


问题#2:

当我开始工作时,将此代码放在我的最佳位置在哪里$ / b $ b应用?在表单加载?在表单加载和Windows窗体设计器之间

生成的代码之间?在模块中?在一个公共子?这是因为我打开并在其他地方编辑数据库,所以我真的不知道怎么做更多

''全球'可用。


问题#3:

(有点偏离主题)或者我应该忘记整个事情......坚持我的数据

图标...并使用SUBST命令创建虚拟驱动器并假装它是什么?


非常感谢


BruceF

VB.net 2003; MS Access db; Netframe 1.1

I wrote an Windows app for my last place of employment that opened and
modified a couple of MS Access db files. I did most of my programming at home
on Drive "C". And I used the Drag/Drop Data Items to create the Connection,
DataSet and DataAdapters.

The Access files were located on drives "P" and "S" at work, so I had VB.net
installed on my work PC so I could change the drives in the Connection Icons.

Now I no longer work at that place and they want me to make some changes. Of
course I can''t as I don''t have a drive P or S on my system. So I''m attempting
to get rid of the Data Icons and do the connection, Data set and adapters with
Code. And of course I''m getting all kinds of errors.

So I''m doing a Test app to find/fix my items. Right off the bat I can''t even
establish a proper connection to a DB. The following is that code I''m using.

I get an ERROR at the FILL line (unhandled exception where "Value cannot be
null". But the access file opens just fine if I use the DATA Icons.

And... If I change the Fill line to:
daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
.... the error then says "The ConnectionString property has not been
initialized".

************** CODE ***********************************************
Imports System.IO
Imports System.Data.OleDb

'' Connection String1 to SHENTSdata.mdb
Dim connString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=TSdbPath & SHENTSdata.mdb"

Dim OleDbConnection1 As OleDbConnection = New OleDbConnection

'' Data Adapter 1
Dim strSelect1 As String
strSelect1 = "SELECT Bill_Code, Dispersmts, Fri_Hrs, Job_Descrn,
Job_Number, Mileage," & _
"Mon_Hrs, Period_End_Date, PO_Order, Sat_Hrs, Sun_Hrs,
Thr_Hrs, Tue_Hrs," & _
"Wed_Hrs, Work_Descrn FROM SHENHrsTable"
Dim daShenData As New OleDbDataAdapter(strSelect1, OleDbConnection1)

'' Dataset 1
Dim dsShenData As New DataSet

'' Fill Dataset 1
daShenData.Fill(dsShenData.Tables("SHENHrsTable"))
''''''daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
************************************************** ******************

QUESTION #1:
How do I fix the No Null value issue (why is it doing this anyways)?

QUESTION #2:
When I get this to work, where is the best place to place this code in my
application? In the Form Load? Between Form Load and "Windows Form Designer
generated code"? In a Module? In a Public Sub? This is because I open and
edit the Data bases elsewhere so I don''t really know how to make it more
''globally'' available.

QUESTION #3:
(a bit off topic) Or should I forget the whole thing... stick with my DATA
Icons... and use the SUBST command to create Virtual Drives and Fake it that
way?

Thanks muchly

BruceF

推荐答案

先生。 B写道:
Imports System.IO
Imports System.Data.OleDb
'''连接String1到SHENTSdata.mdb
Dim connString1 As String = Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = TSdbPath& SHENTSdata.mdb"
Imports System.IO
Imports System.Data.OleDb

'' Connection String1 to SHENTSdata.mdb
Dim connString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=TSdbPath & SHENTSdata.mdb"




不应该是

Dim connString1 As String =" Provider = Microsoft.Jet.OLEDB.4.0 ;数据来源="

& Path.Combine(TSdbPath,SHENTSdata.mdb)


....你在哪里定义了TSdbPath?

如果我正在访问一个资源在

开发和部署环境之间的不同位置,我为每个环境保留单独的web.config文件

并在每个环境中存储相应的字符串。


所以,在web.config中我可能有: -

< configuration>

< appSettings>

< add key =" sqlConnectionString" value =

" Server = WHERE \ EVER; Database = db; Trusted_Connection = true" />

< / appSettings>


等,以及其他web.config中的不同值。


并检索值: -

私有sqlConnectionString As String =

System.Configuration.ConfigurationSettings.AppSettings(" sqlConnectionString")


HTH


Andrew



Shouldn''t that be
Dim connString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& Path.Combine(TSdbPath, SHENTSdata.mdb)

....and where have you defined TSdbPath?
If I''m accessing a resource which is in a different location between the
development and deployment environments, I keep separate web.config files
for each environment and store the appropriate string in each.

So, in web.config I might have:-
<configuration>
<appSettings>
<add key="sqlConnectionString" value =
"Server=WHERE\EVER;Database=db;Trusted_Connection= true" />
</appSettings>

etc, and a different value in the other web.config.

and to retrieve the value:-
Private sqlConnectionString As String =
System.Configuration.ConfigurationSettings.AppSett ings("sqlConnectionString")

HTH

Andrew


> Access文件位于驱动器P上。和S在工作中,所以我在工作PC上安装了

VB.net
> The Access files were located on drives "P" and "S" at work, so I had
VB.net
,这样我就可以在Connection
图标中更改驱动器。
现在我不再在那个地方工作,他们希望我做一些改变。
当然我不能在我的系统上没有驱动器P或S.


什么阻止您右键点击我的网络位置并在你的硬盘上映射一个

适当的pathed子目录作为P或S驱动器?

问题#3:
(有点偏离主题)或者我应该忘记整个事情......坚持我的数据
图标...并使用SUBST命令创建虚拟驱动器并假装它是
那样?
installed on my work PC so I could change the drives in the Connection Icons.
Now I no longer work at that place and they want me to make some changes. Of course I can''t as I don''t have a drive P or S on my system.
What stops you from right-clicking on "My Network Places" and mapping an
appropriate pathed subdirectory on your hard disk as P or S drive?
QUESTION #3:
(a bit off topic) Or should I forget the whole thing... stick with my DATA
Icons... and use the SUBST command to create Virtual Drives and Fake it that way?




SUBST将有效地做同样的事情


Stephen Howe



SUBST will effectively do the same thing

Stephen Howe


除了已经做出的其他观点,当你声明connString1变量并给它分配一个值时,你发布的代码

中没有任何地方你实际使用它。在实例化OleDbConnection对象或

分配给对象的ConnectionString属性时,它不会传递给

connectionString参数。


-

Brendan Reynolds


" Mr。 B" < US ** @ NoWhere.com>在消息中写道

news:ll ******************************** @ 4ax.com ...
In addition to the other points that have been made, while you are declaring
the connString1 variable and assigning a value to it, nowhere in the code
that you have posted do you actually use it. It is not passed to the
connectionString argument when instantiating the OleDbConnection object or
assigned to the ConnectionString property of the object.

--
Brendan Reynolds

"Mr. B" <Us**@NoWhere.com> wrote in message
news:ll********************************@4ax.com...
VB.net 2003; MS Access db; Netframe 1.1

我为我上一个工作地点编写了一个Windows应用程序,它打开并修改了几个MS Access数据库文件。我在驱动器C上的
主页上完成了大部分编程工作。我使用拖放数据项来创建
连接,DataSet和DataAdapter。

Access文件位于驱动器P上。和S在工作中,所以我在我的工作PC上安装了VB.net
所以我可以更改连接
图标中的驱动器。

现在我不再工作了在那个地方,他们希望我做一些改变。
当然我不能,因为我的系统上没有驱动器P或S.所以我试图摆脱数据图标并使用
代码进行连接,数据集和适配器。当然,我遇到了各种各样的错误。

所以我正在做一个测试应用程序来查找/修复我的项目。马上,我甚至不能建立与数据库的正确连接。以下是我正在使用的代码。

我在FILL行得到一个错误(未处理的异常,其中Value not not
null"但是如果我使用DATA图标,访问文件就会打开。

并且...如果我将填充行更改为:
daShenData.FillSchema(dsShenData,SchemaType.Source,& ; SHENHrsTable")
...然后错误说ConnectionString属性尚未初始化。

************ **代码*********************************************
Imports System.IO
Imports System.Data.OleDb
'''连接String1到SHENTSdata.mdb
Dim connString1 As String =" Provider = Microsoft.Jet .OLEDB.4.0;数据
Source = TSdbPath& SHENTSdata.mdb"

Dim OleDbConnection1 As OleDbConnection = New OleDbConnection

''数据适配器1 Dim strSelect1 As String
strSelect1 =" SELECT Bill_Code,Dispersmts,Fri _Hrs,Job_Descrn,
Job_Number,Mileage," &安培; _
Mon_Hrs,Period_End_Date,PO_Order,Sat_Hrs,Sun_Hrs,
Thr_Hrs,Tue_Hrs," &安培; _
  Wed_Hrs,Work_Descrn FROM SHENHrsTable"
Dim daShenData As New OleDbDataAdapter(strSelect1,OleDbConnection1)

''数据集1
Dim dsShenData作为新数据集

''填充数据集1
daShenData.Fill(dsShenData.Tables(" SHENHrsTable"))
''''''daShenData.FillSchema(dsShenData,SchemaType.Source,& ; SHENHrsTable")
****************************************** ******** ******************

问题#1:
如何修复No Null值问题(为什么它仍然这样做)?

问题#2:
当我开始工作时,在我的
应用程序中放置此代码的最佳位置在哪里?在表单加载?在Form Load和Windows Form
Designer
生成的代码之间?在模块中?在一个公共子?这是因为我打开了
并在其他地方编辑了数据库,所以我真的不知道如何让它更全球化。
问题#3:
(有点偏离主题)或者我应该忘记整个事情......坚持使用我的DATA
图标......并使用SUBST命令创建虚拟驱动器并伪造它那个怎么样?

非常感谢

BruceF
VB.net 2003; MS Access db; Netframe 1.1

I wrote an Windows app for my last place of employment that opened and
modified a couple of MS Access db files. I did most of my programming at
home
on Drive "C". And I used the Drag/Drop Data Items to create the
Connection,
DataSet and DataAdapters.

The Access files were located on drives "P" and "S" at work, so I had
VB.net
installed on my work PC so I could change the drives in the Connection
Icons.

Now I no longer work at that place and they want me to make some changes.
Of
course I can''t as I don''t have a drive P or S on my system. So I''m
attempting
to get rid of the Data Icons and do the connection, Data set and adapters
with
Code. And of course I''m getting all kinds of errors.

So I''m doing a Test app to find/fix my items. Right off the bat I can''t
even
establish a proper connection to a DB. The following is that code I''m
using.

I get an ERROR at the FILL line (unhandled exception where "Value cannot
be
null". But the access file opens just fine if I use the DATA Icons.

And... If I change the Fill line to:
daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
... the error then says "The ConnectionString property has not been
initialized".

************** CODE ***********************************************
Imports System.IO
Imports System.Data.OleDb

'' Connection String1 to SHENTSdata.mdb
Dim connString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=TSdbPath & SHENTSdata.mdb"

Dim OleDbConnection1 As OleDbConnection = New OleDbConnection

'' Data Adapter 1
Dim strSelect1 As String
strSelect1 = "SELECT Bill_Code, Dispersmts, Fri_Hrs, Job_Descrn,
Job_Number, Mileage," & _
"Mon_Hrs, Period_End_Date, PO_Order, Sat_Hrs, Sun_Hrs,
Thr_Hrs, Tue_Hrs," & _
"Wed_Hrs, Work_Descrn FROM SHENHrsTable"
Dim daShenData As New OleDbDataAdapter(strSelect1, OleDbConnection1)

'' Dataset 1
Dim dsShenData As New DataSet

'' Fill Dataset 1
daShenData.Fill(dsShenData.Tables("SHENHrsTable"))
''''''daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
************************************************** ******************

QUESTION #1:
How do I fix the No Null value issue (why is it doing this anyways)?

QUESTION #2:
When I get this to work, where is the best place to place this code in my
application? In the Form Load? Between Form Load and "Windows Form
Designer
generated code"? In a Module? In a Public Sub? This is because I open
and
edit the Data bases elsewhere so I don''t really know how to make it more
''globally'' available.

QUESTION #3:
(a bit off topic) Or should I forget the whole thing... stick with my DATA
Icons... and use the SUBST command to create Virtual Drives and Fake it
that
way?

Thanks muchly

BruceF



这篇关于HLP:打开Access数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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