Connect to database using ODBC and dot net.

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
iamthwee iamthwee is offline Offline Sep 3rd, 2009, 8:19 am |
-1
This snippet shows you how to connect to a database using ODBC in vb.net 2005
Quick reply to this message  
Visual Basic 4 / 5 / 6 Syntax
  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
0
milanbillara milanbillara is offline Offline | Oct 18th, 2009
can you tell me the connection to access database using odbc and vb.net please.
 
0
greenarcher371 greenarcher371 is offline Offline | Oct 18th, 2009
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?
 
 

Tags
iamthwee

Message:


Thread Tools Search this Thread



Tag cloud for iamthwee
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC