SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
Visual Basic 2008

How to Connect from Visual Basic .Net to Microsoft SQL Server?

E-mail Print PDF

This article shows you the way to connect from Visual Basic .Net code to Microsoft SQL Server Database. There two ways in this article, first using OLEDB namespace (old style) and second using SQLClient namespace (new style in ADO.Net).

Suppose that Microsoft SQL Server database named: TEST is running on server named: Setha-PC. For SQL Server authentication mode, User ID and password are applied.

I. Using OLEDB namespace

  • Provider - the type of database source (eg. SQLOLEDB.1 for MS-SQL Server)
  • Data Source - name of server where the MS-SQL Server database is located
  • Initial Catalog - the database name
For SQL Server Authentication Mode
Dim cn As New OleDb.OleDbConnection

cn.ConnectionString = "Provider=SQLOLEDB.1; " & _
                      " Data Source='Setha-PC'; " & _
                      " Initial Catalog='TEST'; " & _
                      " User ID=sa; Password='123'"
cn.Open()

MsgBox("Connection establish!")

cn.Close()
For Windows Authentication Mode
Dim cn As New OleDb.OleDbConnection

cn.ConnectionString = "Provider=SQLOLEDB.1; " & _
                      " Data Source='Setha-PC'; " & _
                      " Initial Catalog='TEST'; " & _
                      " Integrated Security=SSPI;" & _
                      " Persist Security Info=False;"
cn.Open()

MsgBox("Connection establish!")

cn.Close()

II. Using SQLClient namespace

  • Data Source - name of server where the MS-SQL Server database is located
  • Database - the database name
For SQL Server Authentication Mode
Dim cn As New SqlClient.SqlConnection

cn.ConnectionString = "Data Source='Setha-PC'; " & _
                      "Database='TEST'; " & _
                      "User ID=sa; Password='123'"
cn.Open()

MsgBox("Connection establish!")

cn.Close()
For Windows Authentication Mode
Dim cn As New SqlClient.SqlConnection

cn.ConnectionString = "Data Source='Setha-PC'; " & _
                      "Database='TEST'; " & _
                      " Integrated Security=SSPI;" & _
                      " Persist Security Info=False;"
cn.Open()

MsgBox("Connection establish!")

cn.Close()
 

How to Check All Printers Status (Idle, Printing, Unknown) in Visual Basic .Net?

E-mail Print PDF

This article shows you the way to write Visual Basic .Net code to check all local existing printers status whether some printers are printing and some are not. The VB code below uses ListView control to display printers status.

Private Sub CheckPrinter()
        Dim Printers As Object
        Dim Printer As Object
        Dim WMIObj As String
        Dim lItem As ListViewItem

        WMIObj = "winmgmts://localhost"
        Printers = GetObject(WMIObj).InstancesOf("win32_Printer")
        'clear list
        Me.lvwPrinter.Items.Clear()
        For Each Printer In Printers
            lItem = Me.lvwPrinter.Items.Add(Printer.name)
            Select Case Printer.PrinterStatus
                Case 3
                    lItem.SubItems.Add("Idle")
                Case 4
                    lItem.SubItems.Add("Printing")
                Case Else
                    lItem.SubItems.Add("Unknown")
            End Select
        Next
End Sub
Download Source Code
 

How to build Visual Basic 2008 project using Microsoft.Jet.OleDb.4.0 on Windows 64 bit?

E-mail Print PDF

This article shows you the way to compile a Visual Basic 2008 project using Microsoft.Jet.OleDb.4.0 on Windows OS 64 bit. By default, we will see the error message [The 'Microsoft.Jet.OleDb.4.0' provider is not registered on the local machine].

The below instructions will help you on the above problem.

  1. Click Project Menu
  2. Click [Project Name] Properties... Menu
    One Windows is appeared.
  3. Click Compile
  4. Click on buttonAdvanced Compile Options...
    One dialog Windows is appeared.
  5. Click on ComboBox Target CPU:
  6. Choose x86
  7. Click button OK
After that, please build the project again for testing.


 

 

 
Video Clip
 

How to Create Popup Menu in Visual Basic .Net 2008?

E-mail Print PDF

This article attaches with a video clip which shows you how to create popup menu in Visual Basic .Net. Popup menu is the menu that can appear when we do right-click on mouse pointer.

Download Sample Here
 

Pascal Triangle in Visual Basic 2008

E-mail Print PDF
The code below produce pascal triangle using Visual Basic 2008 programming language. This sample allows user to enter value of n.
Public Class Form1
    Private Function Factoriel(ByVal n As Integer) As Long
        If n = 0 Then
            Return 1
        Else
            Return n * Factoriel(n - 1)
        End If
    End Function

    Private Sub btnPascal_Click(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) _
                                Handles btnPascal.Click
        Me.Refresh()
        Dim g As Graphics = Me.CreateGraphics
        Dim w As Integer = Me.Width
        Dim x As Long
        For i As Integer = 0 To Me.txtN.Text
            For j As Integer = 0 To i
                x = Factoriel(i) / (Factoriel(j) * Factoriel(i - j))
                g.DrawString(x, New Font("Arial", 10, FontStyle.Regular), _
                             Brushes.Black, w / 2 - 20 * i + 40 * j, i * 20)
            Next
        Next
    End Sub
End Class
Download Source Code Here
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  6 
  •  Next 
  •  End 
  • »


Page 1 of 6