473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Data.Read

Hello,

I am new to this group and I hope someone can help me *g*.

I am good in VBS but now I want to switch to vb.net because of getting crazy while creating every form in VBS with InternetExplorer an HTML.

OK. Now here is my first question:

I have an Access-Database and I want to get some information out of it.

The code works and looks loke this:

----------------------------------------------------------------------------------------------------------
Module Main
Dim i As Integer
Dim strUser As String = Mid(System.Security.Principal.WindowsIdentity.GetC urrent().Name(), System.Security.Principal.WindowsIdentity.GetCurre nt().Name().IndexOf("\") + 2).ToUpper
Dim objKategorien() As Kategorie
Const strDB As String = "D:\Dokumente und Einstellungen\Markus\Eigene Dateien\Visual Studio Projects\ResSolution-Zaehler\ResSolution-Zaehler.mdb"

Public Sub Main()
ReadDB()
End Sub

'Kategorien und akt. Zählerstand aus Access-Datenbank auslesen
Private Sub ReadDB()
Dim connDB1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=" & strDB)
Dim connDB2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=" & strDB)
Dim cmdDB1 As New OleDb.OleDbCommand("SELECT * from Kategorien", connDB1)
Dim cmdDB2 As New OleDb.OleDbCommand("SELECT Zaehlerstaende.Kategorie, Zaehlerstaende.Minuten, Zaehlerstaende.OK FROM(Zaehlerstaende) WHERE (Zaehlerstaende.[User-Kuerzel]='" & strUser & "')
and (Zaehlerstaende.Datum=Date())", connDB2)
Dim drDB1 As OleDb.OleDbDataReader
Dim drDB2 As OleDb.OleDbDataReader

connDB1.Open()
drDB1 = cmdDB1.ExecuteReader()
i = 0
Do While drDB1.Read()
ReDim Preserve objKategorien(i)
objKategorien(i) = New Kategorie
objKategorien(i).ID = drDB1.Item("ID")
objKategorien(i).Bezeichnung = drDB1.Item("Bezeichnung")
connDB2.Open()
drDB2 = cmdDB2.ExecuteReader()
Do While drDB2.Read
If (objKategorien(i).ID = drDB2.Item("Kategorie")) And (drDB2.Item("OK") = False) Then
objKategorien(i).Minuten = drDB2.Item("Minuten")
End If
Loop
drDB2.Close()
connDB2.Close()
i = i + 1
Loop
drDB1.Close()
connDB1.Close()
End Sub
End Module
----------------------------------------------------------------------------------------------
Public Class Kategorie
Public ID As Long
Public Bezeichnung As String
Public Minuten As Integer
End Class
----------------------------------------------------------------------------------------------

It is working very well but do I have to open and close the drDB2 every time?
And why is it not working only with connDB1? I have to Dim connDB2, too, because the compiler says: Dieser Verbindung ist bereits ein geöffneter DataReader zugeordnet, der zuerst geschlossen werden
muss. (The connection is already set to a DataReader witch has to be closed first).
Is there a better way to get the data. Is there something like a DataSet where I can store the result?

Please help me.

Thx, Markus Ellebrecht

P.S. I am german and my english might not be the best. So please foregive me my mistakes *g*

Nov 21 '05 #1
6 1177
Hi Markus!

"Markus Ellebrecht" schrieb
'Kategorien und akt. Zählerstand aus Access-Datenbank auslesen
Oh my god! Everything in german ;-)
Is there a better way to get the data. Is there something like a DataSet
where I can store the result?
DataReader is read-only, forward-only. Have a look at System.Data.DataSet:

Tutorial (in german)
http://www.microsoft.com/germany/ms/...?siteid=542640

Documentation (in german):
http://msdn.microsoft.com/library/de...ClassTopic.asp
P.S. I am german and my english might not be the best. So please foregive
me my mistakes *g*


There is a german newsgroup as well:
news:microsoft.public.de.german.entwickler.dotnet. vb

for ADO.NET
news:microsoft.public.de.german.entwickler.dotnet. datenbank

Cheers

Arne Janning
Nov 21 '05 #2
Markus,

First a question, are you using VBNet with a Visual.Studio Net IDE or with a
Notebook, the last can make it for you a lot more difficult however not
impossible.

For both is a very good page how to do it.
http://samples.gotdotnet.com/quickstart/

In VBNet (certainly with ASPNET) you can forget the module.

You connect your page to your code using a string on the page, however how
to do it depends very much if you use the IDE which does it automaticly or a
notebook or whatever and the VBC compiler. (For me it seems a very hard way
to go using that).

The way you see it in the quickstarts above is by the way again an other
method, because that is a kind of ASPX (VBNET) scripting.

Cor


Nov 21 '05 #3
Hello Arne,

thank u for your answer.
I will switch to the german groups *g*

I will watch your links and i hope it will help...

Greets, Markus Ellebrecht

On Sun, 17 Oct 2004 21:48:38 +0200, "Arne Janning" <sp*****************@msn.com> wrote:
Hi Markus!

"Markus Ellebrecht" schrieb
'Kategorien und akt. Zählerstand aus Access-Datenbank auslesen


Oh my god! Everything in german ;-)
Is there a better way to get the data. Is there something like a DataSet
where I can store the result?


DataReader is read-only, forward-only. Have a look at System.Data.DataSet:

Tutorial (in german)
http://www.microsoft.com/germany/ms/...?siteid=542640

Documentation (in german):
http://msdn.microsoft.com/library/de...ClassTopic.asp
P.S. I am german and my english might not be the best. So please foregive
me my mistakes *g*


There is a german newsgroup as well:
news:microsoft.public.de.german.entwickler.dotnet .vb

for ADO.NET
news:microsoft.public.de.german.entwickler.dotnet .datenbank

Cheers

Arne Janning


Nov 21 '05 #4
Arne,

I did not see this, I will see the reaction of Herfried when this question
comes in his most own particular newsgroup.
news:microsoft.public.de.german.entwickler.dotnet. vb

:-))))

Cor
Nov 21 '05 #5
Markus,

I did mean notepad because your code did look like it was typed in a notepad
for me.

There is an ASPNET resourcekit in those is a lot of usefull information,
extra controls and quickstart, maybe you can take that as sample. Better
you take now I know you have Visual Studio Net that you take this one.

http://msdn.microsoft.com/asp.net/asprk/

With ASPNET you have to remember some things.

The response.redirect is as well used to get the next page
The Session is still and even more important (you eveb can put a dataset in
one time in it)
ASPNET is stateless, what means that nothing is saved between sending and
getting back unless you put it in a session between the send and the
postback

I wrote it the postback, that is important.

The load event is forever fired. In that you have to use the statement.

If Not Ispostback then

Else

End if

Beside the session is the viewstate (everything is sended everytime), a
shared class however that is for the application what means for all users
active on your server in a session and as well the cache what is almost the
same as a shared cache and therefore usefull, however wait untill you need
that.

I think I have give you for now enough information.

I hope this helps somehow?

Cor

I hope this helps a little bit?

Cor
Nov 21 '05 #6
Hi Cor!

"Cor Ligthert" schrieb
There is an ASPNET resourcekit in those is a lot of usefull information,
extra controls and quickstart, maybe you can take that as sample. Better
you take now I know you have Visual Studio Net that you take this one.

http://msdn.microsoft.com/asp.net/asprk/

With ASPNET you have to remember some things.

The response.redirect is as well used to get the next page
Keep in mind that may as well be used to get the previous page.
The Session is still and even more important (you eveb can put a dataset
in one time in it)
Actually every web server can have multiple sessions. So there is not "The
Session" there are "Sessions". I think this is to improve performance.
ASPNET is stateless, what means that nothing is saved between sending and
getting back unless you put it in a session between the send and the
postback
HTTP is stateless as it has been specified by a supra-natinal commitee.
ASP.NET has been built in building 42, Bellvue, Washington, USA and
therefore might not be stateless.
I wrote it the postback, that is important.
Full ACK.
The load event is forever fired. In that you have to use the statement.

If Not Ispostback then
Return ToSender
Beside the session is the viewstate (everything is sended everytime), a
shared class however that is for the application what means for all users
active on your server in a session and as well the cache what is almost
the same as a shared cache and therefore usefull, however wait untill you
need that.

I hope this helps a little bit?


A little bit, yes, thanks. You know, germans...

Cheers

Arne
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1433
by: Gonçalo Rodrigues | last post by:
Hi, I have a problem with threads and sockets. I'll try to describe the problem in words with pseudo-code. I've been working on a few classes to make it easier to work with threads. This...
10
2313
by: crawlerxp | last post by:
This is the problem: I do not get the output I need when encoding and decoding data using rijndael alghoritm. Look at the code and see what the problem is actually: Please paste this code into...
13
10972
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip...
7
5475
by: c duden | last post by:
I am attempting to encrypt some text and be able to decrypt it at a later time. I have two methods to do this: public static Byte EncryptText(string textToEncrypt, string encryptionHash) {...
11
6592
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
0
3910
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
9
2179
by: Nathan Sokalski | last post by:
I am trying to connect to a Microsoft Access Database from my ASP.NET Application. I use the following code to create my connection string: cmdSelect.Connection = New...
5
8925
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
6
3511
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
43
2311
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.