How-to with Databases?
How-to with Databases?
How-to with Databases?
How-to with Databases?
How-to with Databases?
How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases?
How-to with Databases? How-to with Databases?
How-to with Databases?
Go Back  Xtreme Visual Basic Talk > > > How-to with Databases?


Reply
 
Thread Tools Display Modes
  #1  
Old 10-25-2006, 04:42 PM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default How-to with Databases?


hi,

i just moving from VB6 to VB.NET and i see that it's totally different :-( can somebody 'translate' my old connection and select to VB.NET please?

my old code:
Dim DB As Database
Set DB = OpenDatabase(App.Path + "\mydb.mdb")
Dim TR As Recordset
Set TR = DB.OpenRecordset("SELECT ID, Name, ....")
Do Until TR.EOF
Print TR.Fields("ID")+" - "+TR.Fields("Name")
Loop


something simple... and if you know where i can find more 'easy' examples please let me know ;-)

Tomas
Reply With Quote
  #2  
Old 10-26-2006, 04:22 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by tominko
hi,

i just moving from VB6 to VB.NET and i see that it's totally different :-( can somebody 'translate' my old connection and select to VB.NET please?

my old code:
Dim DB As Database
Set DB = OpenDatabase(App.Path + "\mydb.mdb")
Dim TR As Recordset
Set TR = DB.OpenRecordset("SELECT ID, Name, ....")
Do Until TR.EOF
Print TR.Fields("ID")+" - "+TR.Fields("Name")
Loop


something simple... and if you know where i can find more 'easy' examples please let me know ;-)

Tomas

i've found solution :-)
1., in menu 'Project' -'Add Reference' add adodb
2., some changes in code and it's done
code:
Dim DB As ADODB.Connection
DB = New ADODB.Connection
Dim RS As New ADODB.Recordset
DB.CursorLocation = ADODB.CursorLocationEnum.adUseClient
DB.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "\mydb.mdb;")
RS.Open("SELECT ID, Name, ....", DB)
RS.MoveFirst()
Do Until RS.EOF
Debug.Print(RS.Fields("ID").Value & "-" & RS.Fields("Name").Value)
RS.MoveNext()
Loop
Reply With Quote
  #3  
Old 10-26-2006, 06:06 AM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

I would suggest looking into the OleDB Namespace . It works faster than an ADODB connection and is designed for the .Net framework.
Reply With Quote
  #4  
Old 10-26-2006, 07:00 AM
reboot's Avatar
rebootHow-to with Databases? reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

You really don't want to use classic ADO in .Net, I'd suggest a good book.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #5  
Old 10-26-2006, 10:44 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by reboot
You really don't want to use classic ADO in .Net, I'd suggest a good book.
i have some books but everywhere i've found just too complicated how to do this, i'll be happy if you give me example how to do
Reply With Quote
  #6  
Old 10-26-2006, 12:57 PM
reboot's Avatar
rebootHow-to with Databases? reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #7  
Old 10-26-2006, 03:32 PM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by reboot
i think if you really good that for you is less than 1 minute to write the code ...but probably more easy is sent me to msdn search
Reply With Quote
  #8  
Old 10-26-2006, 09:33 PM
reboot's Avatar
rebootHow-to with Databases? reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

I get paid for writing code. Would you like a quote?
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #9  
Old 10-27-2006, 01:48 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by reboot
I get paid for writing code. Would you like a quote?
probably i missed the reason of this forum it's not here for help?
Reply With Quote
  #10  
Old 10-27-2006, 06:20 AM
reboot's Avatar
rebootHow-to with Databases? reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

Quote:
Originally Posted by tominko
.... for you is less than 1 minute to write the code ....
We are most certainly here to help. We are, however, not here to write code for you.

ADO.Net is a very complicated topic. Tutoring individuals on subjects such as this go way beyond the scope of this forum. You're going to have to at least get the basics on your own. Then we'll be able to help you efficiently.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #11  
Old 10-27-2006, 07:17 AM
wayneph's Avatar
waynephHow-to with Databases? wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Just to give an example, I have a 700+ page book on ADO.NET 1.1 and a 500+ page book on ADO.NET 2.0. It's hard to put that into a thread.

Here is a link to a MS tutorial on Getting Started with Data Access. It will give you some samples, but it still won't replace your own research to figure it out. Copy and Pasting it into your application will cause more headaches down the road because you still won't know what it's doing.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #12  
Old 10-27-2006, 11:36 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by wayneph
Just to give an example, I have a 700+ page book on ADO.NET 1.1 and a 500+ page book on ADO.NET 2.0. It's hard to put that into a thread.

Here is a link to a MS tutorial on Getting Started with Data Access. It will give you some samples, but it still won't replace your own research to figure it out. Copy and Pasting it into your application will cause more headaches down the road because you still won't know what it's doing.
i have about 10 books for .net (including ado.net) but i can't find solution for wht i want. i learn perl by my self and i've got certificate for it now and my sources was just examples and just some answers from friends. i thing that i know programming in visual basic 6 (i start with vb about 10 years ago) - i made some preogramms that people use everyday but now i want to 'upgrade' to .net and i wondering how is everything different. Yesterday i start to 'fight' with treeview and i can't understand why, for example, i cant add key if i inserting new node - example:
TreeView.Nodes.Add("SH_0", "My Items")
TreeView.Nodes("SH_0").Nodes.Add("SH_22", "RRRRR")) << not working after 2nd level [TreeView.Nodes("SH_22").Nodes.Add("SH_28", "UUUU"))]
TreeView.Nodes("SH_0").Nodes.Add(New TreeNode("RRRR")) << this is working but i need to set 'key' for it for add another level


like in VB6:
TreeView.Nodes.Add , , "SH_0","My Items"
TreeView.Nodes.Add "SH_0", tvwChild, "SH_22","RRRRR"
.....


or the example with database connect and do select

all i need is working examples where i can learn better like from msdn libraries or books then if you can give me lots of examples i'll be happy
Reply With Quote
  #13  
Old 10-27-2006, 11:51 AM
reboot's Avatar
rebootHow-to with Databases? reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

MSDN has tons of code samples available for download.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #14  
Old 10-27-2006, 11:55 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by reboot
MSDN has tons of code samples available for download.
but not that i want... no problem, i'll find it alone :-) ...thanx for help
Reply With Quote
  #15  
Old 10-27-2006, 11:56 AM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default

a good place to start in your change over to .net would be this post from the general .net forum

/!\ IMPORTANT HINTS /!\ VB6 programmers moving to .NET

This will give you an idea of some do's and dont's

and there is this link within that page http://msdn2.microsoft.com/en-us/library/kehz1dz1.aspx

This page will give you a more solid basis on WHY things are different, from there you should be able to work through things easier

not to mention that this forum has a code library

http://www.xtremevbtalk.com/code-library/

where you might be able to find some practical applications of some changes you'll need to make. I would advise the FIRST link, then the second, then the third, its better to know WHY something is different than just knowing that this black box of a piece of code works 'for some reason'
Reply With Quote
  #16  
Old 10-27-2006, 12:14 PM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

Quote:
Originally Posted by torpkevuk
a good place to start in your change over to .net would be this post from the general .net forum

/!\ IMPORTANT HINTS /!\ VB6 programmers moving to .NET

This will give you an idea of some do's and dont's

and there is this link within that page http://msdn2.microsoft.com/en-us/library/kehz1dz1.aspx

This page will give you a more solid basis on WHY things are different, from there you should be able to work through things easier

not to mention that this forum has a code library

http://www.xtremevbtalk.com/code-library/

where you might be able to find some practical applications of some changes you'll need to make. I would advise the FIRST link, then the second, then the third, its better to know WHY something is different than just knowing that this black box of a piece of code works 'for some reason'
thanx but still not found solution for treeview problem ...i thik is more easily to start with C++ because with vb.net i need to start from beginning as well
Reply With Quote
  #17  
Old 10-30-2006, 02:26 PM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default again easy solution

Code:
Dim ConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "\MyDb.mdb;" Using connection As New OleDb.OleDbConnection(ConnectionString) Dim command As New OleDb.OleDbCommand("SELECT * FROM Categories ORDER BY Root_ID ASC", connection) connection.Open() Dim reader As OleDb.OleDbDataReader = command.ExecuteReader() While reader.Read() Debug.Print (reader("ID") & ", " & reader("Name")) End While reader.Close() connection.Close() End Using
Reply With Quote
  #18  
Old 10-30-2006, 02:31 PM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default Strange problem with query

Code:
Debug.Print("UPDATE Categories SET Root_ID=" & Mid$(NodX.Parent.Name, 4) & " WHERE ID=" & Mid$(NodX.Name, 4)) Dim ConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "\MyDb.mdb;" Using connection As New OleDb.OleDbConnection(ConnectionString) connection.Open() Dim command As New OleDb.OleDbCommand("UPDATE Categories SET Root_ID=" & Mid$(NodX.Parent.Name, 4) & " WHERE ID=" & Mid$(NodX.Name, 4), connection) command.ExecuteNonQuery() connection.Close() End Using

in debug is printed CORRECT query
"UPDATE Categories SET Root_ID=16 WHERE ID=12"

but if i look to database that the query is not done :-(
can somebody help sooner than i kick my pc?

Last edited by tominko; 10-30-2006 at 02:48 PM. Reason: spelling mistakes :-)
Reply With Quote
  #19  
Old 11-05-2006, 12:36 AM
tominko tominko is offline
Newcomer
 
Join Date: Oct 2006
Posts: 24
Default

i don't have option strict on (i don't know what is it )

and mid$() i using because in treeview is more 'sections' which have different 'key' like 'MI_0', 'TX_0'... and the zero is id number from database which can be used like 'Root_ID' for another items - 'MI_3' with Root_ID 'MI_0' is child of 'MI_0'....

i know that i'm not perfect in vb and i dont use technique like 'profi' but all my programms are working without any problems
Reply With Quote
  #20  
Old 11-05-2006, 01:53 AM
MikeJ's Avatar
MikeJHow-to with Databases? MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Visual Basic.NET Books
We have three very good recommendations in this thread for ADO.NET books.


Option Strict On forces data types to be converted, rather than the usual lazy method that most programmers take and rely on implicit type conversion. It also helps keep precision by forcing you to be so precise. See http://msdn.microsoft.com/library/de...tionStrict.asp

You really should not use Legacy functions in .net, in the case of Mid$, you should use the Substring method of the string object. Also, in regards to the treeview, it is easier than ever to check which nodes are parents/children, etc. You just need to iterate through each node to see. Check out the TreeView control in MSDN as well.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How-to with Databases?
How-to with Databases?
How-to with Databases? How-to with Databases?
How-to with Databases?
How-to with Databases?
How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases? How-to with Databases?
How-to with Databases?
How-to with Databases?
 
How-to with Databases?
How-to with Databases?
 
-->