944,014 Members | Top Members by Rank

Ad:
  • VB.NET Code Snippet
  • Views: 5308
  • VB.NET RSS
0

Connect to database using ODBC and dot net.

by on Sep 3rd, 2009
This snippet shows you how to connect to a database using ODBC in vb.net 2005
VB.NET Code Snippet (Toggle Plain Text)
  1. Imports System.Data.Odbc
  2.  
  3. Public Class Form1
  4.  
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7.  
  8. Dim myConnection As OdbcConnection = New OdbcConnection()
  9. myConnection.ConnectionString = "Dsn=epic;uid=SYSPROG;host=server4;port=8350;db=mfgsys803"
  10.  
  11. myConnection.Open()
  12.  
  13.  
  14. Dim cmdtxt As String
  15. ' Dim no As Integer
  16. Dim myCommand As New OdbcCommand()
  17.  
  18. 'Try
  19. ' conection.Open()
  20. 'Catch ex As Exception
  21.  
  22. 'End Try
  23. myCommand.Connection = myConnection
  24. Dim myAdapter As New OdbcDataAdapter
  25.  
  26.  
  27.  
  28. cmdtxt = "SELECT pub.Part.PartNum, pub.Part.ClassID FROM PUB.Part Part WHERE pub.Part.PartNum='50101001'"
  29.  
  30. 'cmdtxt = "SELECT pub.Part.PartNum FROM pub.Part"
  31.  
  32. MessageBox.Show(cmdtxt)
  33.  
  34.  
  35. myCommand.CommandText = cmdtxt 'start query
  36. myAdapter.SelectCommand = myCommand
  37.  
  38. Dim moddata As OdbcDataReader
  39.  
  40. moddata = myCommand.ExecuteReader()
  41.  
  42.  
  43. While moddata.Read = True
  44. Try
  45. MessageBox.Show(moddata(1))
  46. Catch ex As Exception
  47. MessageBox.Show(ex.Message)
  48. End Try
  49. End While
  50.  
  51. moddata.Close()
  52.  
  53.  
  54. myConnection.Close()
  55.  
  56. End Sub
  57. End Class
Comments on this Code Snippet
Oct 18th, 2009
0

Re: Connect to database using ODBC and dot net.

can you tell me the connection to access database using odbc and vb.net please.
Newbie Poster
milanbillara is offline Offline
1 posts
since Oct 2009
Oct 18th, 2009
0

Electronice photo album

give me example code for electronic photo album by use dragging the image to the other position or other frame, example image1 with picture input drag to image2 no picture input by using mouse control and code for locating file in listcommand?
Newbie Poster
greenarcher371 is offline Offline
1 posts
since Oct 2009
Mar 2nd, 2010
0

Re: Connect to database using ODBC and dot net.

i have been having some problems with this coding m8 do u mind give me more information on:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myConnection As OdbcConnection = New OdbcConnectio () myConnection.ConnectionString = " "

Please help me out
this is my email: H_W_S.oforikue.16@hotmail.com

anyone that know not only author of code if u know more about this piece of coding cos it is not working
Newbie Poster
SoftwarePaladin is offline Offline
3 posts
since Mar 2010
Mar 2nd, 2010
0

Re: Connect to database using ODBC and dot net.

yea about my earlier post i figured it out ty
Newbie Poster
SoftwarePaladin is offline Offline
3 posts
since Mar 2010
Nov 4th, 2010
0

connection string in vb.net

Click to Expand / Collapse  Quote originally posted by iamthwee ...
This snippet shows you how to connect to a database using ODBC in vb.net 2005
can you please tell me how to get the connection string ?
Newbie Poster
sukanya1990 is offline Offline
1 posts
since Nov 2010
Message:
Previous Thread in VB.NET Forum Timeline: String to values
Next Thread in VB.NET Forum Timeline: Cant figure this out...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC