Read Data from Oracle Database using Visual Basic .Net 2010

0 comments

Posted on 1st December 2011 by Admin in Visual Basic .Net |Visual Basic 2010

, ,

Sample code on how to access or retrieve data from Oracle database using visual basic .net 2010. Please add to reference the ODP.NET DLL to your visual studio reference in order to gain access to your oracle database server.

 

 

 

 


 

‘Sample Code Below

Imports Oracle.DataAccess.Client ‘ Visual Basic ODP.NET Oracle managed provider

Public Class frmdepartment

Private Sub frmdepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oradb As String = “Data Source=(DESCRIPTION=(ADDRESS_LIST=” _
+ “(ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=hr;Password=hr;”

Dim conn As New OracleConnection(oradb) ‘ Visual Basic
conn.Open()

Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = “select department_id, department_name, location_id from departments” ‘ VB
cmd.CommandType = CommandType.Text

Dim dr As OracleDataReader = cmd.ExecuteReader()
While dr.Read()
ListBox1.Items.Add(“The ” + dr.Item(“department_name”) + _
” department is in ” + dr.Item(“location_id”).ToString())
End While

dr.Dispose()
cmd.Dispose()
conn.Dispose()
End Sub

End Class

Visual Basic 2010 Express Connect to MySQL Database

0 comments

Posted on 11th July 2011 by Admin in Visual Basic .Net |Visual Basic 2010

, ,

This tutorial will guide you on how to connect MySQL Database to your visual basic 2010 express. Visual basic 2010 express doesn’t show a wizard connection to MySQL database; please see the picture in figure 1 it shows 3 data sources only Microsoft Access Database File, Microsoft SQL Server Compact 3.5 and Microsoft SQL Database File. It means you cannot connect your MySQL Database file using the data source wizard.

Figure 1.Follow these few steps to connect your MySQL Database to Visual Basic 2010 Express

1. Download and install the MySQL Connector Net 6.4.3 which is can be downloaded at this link
http://dev.mysql.com/downloads/connector/net/
2. Open your visual basic 2010 express and create a new project as shown in the picture below.

3. Next step, go to the ‘Project’ menu and click the ‘Add Reference’, check the picture below.

4. Add Reference form will show and by default Project tab, select the Browse tab and locate the MySql.Data.dll

For Windows Vista file located at Program Files->MySQL->MySQL Connector Net 6.4.3->Assemblies->v4.0->MySql.Data.dll

For Windows 7 file located at Program Files (x86)->MySQL->MySQL Connector Net 6.4.3.->Assemblies->v4.0->MySql.Data.dll

5. After adding the MySql.Data.dll reference then you are now ready to connect your MySQL database with visual basic 2010 express. Please try it to yourself or you may follow the sample code provided below.

Code for VB.Net 2010 Express

Imports MySql.Data.MySqlClient
Public
Class Form1

Dim
con As MySqlConnection = New MySqlConnection(“Data Source=192.168.1.104;Database=test;User ID=root;Password=mypassword;”)

Dim
sql As MySqlCommand = New MySqlCommand(“SELECT * FROM Employee”, con)

Dim
ds As DataSet = New DataSet()

Dim
DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()

Dim
Comb As MySqlCommandBuilder

‘Please add datagridview to your form and name it datagrid1
‘This will display the data to datagrid view

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

con.Open()

DataAdapter1.SelectCommand = sql

DataAdapter1.Fill(ds, “Employee”)

DataGridView1.DataSource = ds

DataGridView1.DataMember = “Employee”

con.Close()

End
Sub

‘Update database. Change any data from datagrid then click this button it will save any changes from the grid
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Comb = New MySqlCommandBuilder(DataAdapter1)

Dim
i As Integer = DataAdapter1.Update(ds.Tables(“Employee”))

MessageBox
.Show(“modify the number “ & i.ToString & ” rows”)

End
Sub

‘Sample insert record to MySQL database
Private
Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim
MyCommand As New MySqlCommand

con.Open()

MyCommand.Connection = con

MyCommand.CommandText = “INSERT INTO Employee(IDNo,FirstName,LastName,email) VALUES( ‘” & txtID.Text & “‘,’” & txtfirstname.Text & “‘,’” & txtlastname.Text & “‘,’” & txtemail.Text & “‘)”

MyCommand.ExecuteNonQuery()

con.Close()

MsgBox(“Record successfully added!”)

End Sub

End Class

Hello World in Visual Basic 2010 Sample

0 comments

Posted on 8th July 2011 by Admin in Video Tutorial |Visual Basic .Net |Visual Basic 2010

Description

A simple visual basic 2010 program that will show the message “Hello World”. In this tutorial you need one form with the caption name “Hello World” and one button object called button1 as shown the code below. When user hit the button, it will popup the message “Hello World”.

Programming Code

‘A “Hello, World!” program in Visual Basic .net.

Public Class Form1
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Msgbox
("Hello, World")
End
Sub

‘Close sample code for vb.net

Sub
btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
Me
.Close()
End
Sub

End Class

Send Mail in Visual Basic 2010 and 2008

0 comments

Posted on 9th May 2010 by reyman in Visual Basic 2008 |Visual Basic 2010

, , ,

Project On How Send Mail in Visual Basic 2008Visual Basic 2010 and 2008 sample on how to send email using SMTP Server.

Internet Information Services (IIS) is required to send email via visual basic 2008.

* TheSmtpServerproperty must be set to the IP address or server name where the SMTP Server is running. In most cases this is the “localhost” computer. Therefore, theSmtpServerproperty value can be either the friendly name, “localhost”, or “127.0.0.1″. The latter is the default for this application.

* To find the SMTP server nameOpen the IIS snap-in (InControl Panel, openAdministrative Tools, and then openInternet Information Services).
* Expand theDefault SMTP Virtual Servernode.

* ClickDomains. In the right pane you will see a list ofDomain Names. You may set theSmtpServerproperty to one of these names or its corresponding IP address.
* The Default SMTP Virtual Server must also be running. Be aware that it is possible for the SMTP Service to be running, but the Default SMTP Server in IIS to be stopped. There is a difference between the service itself and the actual server run by the service. If your Default SMTP Virtual Server is not running, a red X icon will be visible over its node in the IIS snap-in.

To start the server, right-click its node and clickStart

* Set the relay restrictions:

* In IIS, right-clickDefault SMTP Virtual Serverand selectProperties.

* In thePropertiesdialog box click theAccesstab.ClickRelay.

* In theRelay Restrictionsdialog box, select the box labeledAll except the list below. The bottom check box can be selected or cleared.

Download Send Mail in Visual Basic 2008
Extract Password : sendmail1000

Download Send Mail in Visual Basic 2010
Extract Password: sendmailvb2010

Visual Basic 2010 – XML Comments Sample

0 comments

Posted on 4th May 2010 by Admin in Visual Basic 2010

,

This sample demonstrates creating XML comments, viewing them in the editor, and accessing them programmatically.

TheAutomobileclass defines the following type elements, each of which demonstrates a different aspect of XML comments:

  • TypesAutomobileandEngineOption
  • PropertiesModel
  • MethodsConstructors,Upgrade,CalculateMaxTowing,WillItTow
  • EventsNeedsTuneUp
  • DelegatesRotateTires,ReplaceSparkPlugs
  • Fieldscar,modelValue

TheClickevent handler for theCreate Carbutton calls several of theAutomobilemembers. When using IntelliSense in theCode Editor, the XML comments are displayed as ToolTips.

TheClickevent handler for theList Summariesbutton uses theXmlDocumentclass to query the XML file that contains the XML comments. When the project is compiled, this XML file is created and stored with the project assembly. TheCompiletab of theProject Designerenables you to specify the location and name of this file.

Download Project