SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
SETHA SITE INFORMATION

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
 

What is Algorithm in Computer Science?

E-mail Print PDF

Algorithm is a process of problem-solving in step by step to get result. Algorithm is very importance for programmers to do computer programming because it figures out the programming process. Algorithm is a part of problem-solving techniques. After the problem has been raise, we have to analyze the problem first then the inputs and outputs are defined. After that we start to design the algorithm that is a process to transform inputs into outputs.

Problem-solving technique



 
Example
 
Problem: Given the values of parameters a, b and c. Design algorithm to find root x of the equation ax+b=c.

After problem has been raised, we have to do the analysis.

Analyze:
  • What are the results of the problem? (outputs)
    =>That is value of x
  • What is the information we do need to find solution? (inputs)
    =>Value of parameter a
    =>Value of parameter b
    =>Value of parameter c
  • How to transform inputs into output? (processes and formulas)
    =>If (a=0 and c-b=0) then x has infinite root
    =>if(a=0 and c-b#0) then x has no root
    =>otherwise x=(c-b)/a
Algorithm:
1. Get value of a
2. Get value of b
3. Get value of c
4. Calculate x with the following formula
   if a not equal to 0 then
        x=(c-b)/a
   otherwise
        if c-b=0 then Show "x has infinite root"
        otherwise Show "x has no root"
 

How to Make ACCDE file in Microsoft Access 2010 (MDE in Microsoft 2003)?

E-mail Print PDF

This article shows you the way to make Microsoft Access 2010 ACCDB file into the ACCDE file which equivalent to the MDE file in Microsoft Access 2003.

If you develop database by creating Access Form, Access Report and VBA in Microsoft Access 2010 then your database file will be extension .ACCDB (eg. data.accdb) (which is the .MDB file in Microsoft Access 2003). To avoid other people viewing the VBA code in your file you have to convert the .ACCDB file into .ACCDE file (in Microsoft Access 2003 is converting from .MDB to .MDE).

To begin just open the Microsoft Access 2010 Database and follow the instructions below:

  1. Click Home Tab
  2. Click Save & Publish
  3. Click Save Database As
  4. Click Make ACCDE
  5. Click Button Save As
  6. Choose File Location
  7. Save

 


Page 2 of 19