Tag: example

SQL Conditional Record Update

A Visual Basic example on how to update a record if it exists or insert it if it doesn’t.

Sub RecordStandardizedComputer(WS As String)
  Dim txt1 As String, txt2 As String, txt3 As String
  Dim xSQL As String

 txt3 = "SELECT ComputerID from LOG_ComputersStandardized" _
 & " where ComputerName = " & WS

 txt2 = "INSERT INTO LOG_ComputersStandardized (ComputerName, RunTime)" _
 & "VALUES (" & WS & "','" & Now.ToString & "')"

 txt1 = "UPDATE LOG_ComputersStandardized SET " _
   & " DateTime = '" & Now.ToString & "'" _
   & " WHERE ComputerName = '" & WS & "'"

 xSQL = "IF NOT EXISTS (" & txt3 & ")" & txt2 & " ELSE " & txt1
  ExecuteSqlCommand(xSQL)
  End Sub

Windows 7 taskbar not responding

Click Start

Type: CMD, from the results, right click CMD

Click ‘Run as Administrator’

At the Command Prompt, type: sfc/scannow

This will check for any integrity violations

Restart your system

  1. Insert the Windows 7 DVD
  2. Restart your computer
  3. When asked if you want to boot from your DVD drive, do so.
  4. Choose your language, click Next.
  5. Click ‘Repair your computer’
  6. Select operating system you want repair.

Generate Random String

randomstring

 

Imports System.Text
 
Public Class Form1
 
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim s As String = “ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz”
    Dim r As New Random
    Dim sb As New StringBuilder
 
    For i As Integer = 1 To 8
      Dim idx As Integer = r.Next(0, 61)
      sb.Append(s.Substring(idx, 1))
    Next
 
    TextBox1.Text = sb.ToString
  End Sub
End Class

Read MAC Addresses in VB.NET

The following code is a working example for determining the MAC address of your network card.

Imports System.Net.NetworkInformation

Public Class Form1
  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    MessageBox.Show(getMacAddress)
    End
  End Sub

  Function getMacAddress()
    Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
    Return nics(1).GetPhysicalAddress.ToString
  End Function

End Class

SQL Date Range Examples

Today

SELECT EventTime, Event, AppTitle, AppVersion
FROM LOG_AutomatedApplicationRunTime
WHERE EventTime >= DATEADD(d, 0, DATEDIFF(d, 0, GetDate()))
ORDER BY EventTime

Past 30 Days

SELECT EventTime, Event, AppTitle, AppVersion
FROM LOG_AutomatedApplicationRunTime
WHERE EventTime < DATEADD(day, – 30, GETDATE())
ORDER BY EventTime