15 May 2009

Video: Microsoft Visual Studio 2008 - How to create DELETE SQL statement visually


The above video shows you how to create a DELETE SQL statement with Microsoft Visual Studio 2008.  SQL statement can be created visually by clicking and dragging, etc. 

After creating it, you can copy the SQL code too.

Essential steps:

  1. To open Server Explorer, click “View” > “Server Explore”
  2. Create new query.
  3. Select table(s).  Add table(s).
  4. Change query to “Delete” type. i.e. “Change Type” > Delete
  5. Key in the Delete criteria.
  6. Execute SQL statement (DELETE).

08 May 2009

VB.Net code: ADO.Net – Insert a record to a table

'Insert a record into customer table
'note: CustomerID is nchar(5). Primary Key
Dim sql As String = "INSERT INTO Customers " & _
    "(CustomerID, CompanyName, ContactName, ContactTitle) " & _
    "VALUES ('" & strCustomerID & "','" & _
                         strCompanyName & "','" & _
                         strContactName & "','" & _
                         strContactTitle & "')"

Dim connStr As String = "server=localhost; uid=sa; password=myPassWord; database=Northwind"
Dim conn As SqlConnection = New SqlConnection(connStr)
Dim comm As SqlCommand = New SqlCommand(sql, conn)

conn.Open()
Dim intRowsAdded As Integer
intRowsAdded = comm.ExecuteNonQuery()
'You can use the ExecuteNonQuery to update/delete record too.

conn.Close()
conn = Nothing
comm = Nothing

You might need to modify the some VB code.  Example:
server=.\sqlexpress; uid=sa; pasword=wna05;
- for accessing MS SQL Express in the localhost

or, server=myComputerName\sqlexpress -depends on your notebook configuration

07 May 2009

VB.Net code: How to pass a public variable intIndex between windows forms

This is an example of passing a public variable intIndex from from1 to form2.

Step 1: Delclare the variable intIndex in Form1 as follows.

 

Public Class Form1

 Inherits System.Windows.Forms.Form

 Public Shared intIndex As Integer

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

       intIndex = TextBox1.Text

 Dim myForm As New Form2

       myForm.Show()

 End Sub

 

Step 2: How the form2 access the intIndex variable.

 

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As

 System.EventArgs) Handles MyBase.Load

 TextBox1.Text = Form1.intIndex

End Sub

 

Other note:

Me.close() - to close the form.