Friday, October 27, 2006

clears all of the dynamically generated controls

This subroutine clears all of the dynamically generated controls .
It does this by removing all of the controls, then calling the InitializeComponent() subroutine that was automatically generated by Visual Studio .NET.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Clear all the controls.
Controls.Clear()
' Re-Add all of the original controls
InitializeComponent()
' Reset the m_Location to its original location.
m_Location = New Point(10, 10)
' Reset the number of controls.
m_ControlCount = 0
' Show the form again.
Show()
End Sub

Insert graphic objects dynamically

A word document is available in this address:

http://www.box.net/public/irqldpcze3

Important things:

1. Create, set and add to Controls; new graphic objects:

' Set up some properties for the TextBox
btnSpeakText.Text = "Speak Text"
btnSpeakText.Name = "btnSpeakText"
btnSpeakText.Location = New Point(m_Location.X + 250, m_Location.Y)
btnSpeakText.Size = New Size(100, btnSpeakText.Height)
' Add the previously created TextBox to this button
btnSpeakText.Tag = txtSpeakText
' Add the TextBox to the controls collection.
Controls.Add(btnSpeakText)

2.- Work with msgBox specific(OK):

MsgBox("You've reached 5 controls. Clear controls to start again.", _
MsgBoxStyle.OkOnly, Me.Text)

3.- Join Handles and subrutines:

AddHandler btnSpeakText.Click, AddressOf SpeakTextClickHandler

4.- Ask for the sort of object:

If TypeOf sender Is Button Then
End If

5.- Castings:

Dim myButton As Button = CType(sender, Button)

Insert graphic objects dynamically

ff

Sunday, October 22, 2006

ACCESS: ExecuteNonQuery

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

Dim conn As OleDbConnection = Nothing
Dim cmd As OleDbCommand = Nothing
Dim sql As String = Nothing
Dim ConnectionString As String = Nothing

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\BD_EMP.mdb"

conn = New OleDbConnection()
conn.ConnectionString = ConnectionString
conn.Open()

sql = "INSERT INTO CLIENTS(ID_CLIENT) VALUES ('ID_10') "
cmd = New OleDbCommand(sql, conn)

Try
cmd.ExecuteNonQuery()
Catch ae As OleDbException
MessageBox.Show(ae.Message.ToString())
Finally
conn.Close()
End Try
End Sub

Saturday, October 21, 2006

What's is new in ADO .NET?

You can do a lot with Visual Basic by itself, but ultimately, you have to have data to build most systems. VB .NET is designed to work with a new way to access data: ADO .NET.

The simplest definition of ADO .NET is that it is Microsoft's new object library for data access. In one way, this is just the most recent of Microsoft's access methods (previous products were DAO, RDO and ADO). But in another way, this is a new revolution in software like the other .NET products.

The ADO .NET namespace is in System.Data.dll. The default Windows Application project already adds a reference to that DLL, but it's worthwhile to make sure that it's there on your computer.

The objects that are in ADO .NET are roughly split into two groups — content components and managed-provider components. The content components essentially hold actual data and include these classes:

DataSet
DataTable
DataView
DataRow
DataColumn
DataRelation

The managed-provider components interact with the database for data retrievals and updates.

These components include:

connection
command
data adapter
data reader

The names above are "generic" (note that they're not capitalized) because unique managed-provider components are used with different "providers" (software interfaces for actual databases). There are two that are currently included with ADO .NET. SqlClient is used with Microsoft's SQL Server database and OleDb for everything else. For example, SqlClient contains SqlDataReader and OleDb contains OleDbDataReader.

The main new feature in ADO .NET is provided by the DataSet object. This object reads the database and creates an in-memory copy of that part of the database that your program needs. DataSet is a little (but only just a little) like the old Recordset object. Usually a DataSet object will correspond to a real database table or view (or perhaps several), but DataSet is a "disconnected" view of the database data. After ADO .NET creates the data set, there is no longer an active connection to the database. This helps a lot in scalability (when the amount of data that must be handled by the same program increases) because your program only has to connect with a database server when reading or writing from the database.

One of the biggest differences between DataSet and the old Recordset is that data in ADO.NET is transported in XML format. That makes it a structured text document that can be read by anyone on any platform. This makes DataSet "interoperable" between a lot of computers - Microsoft and non-Microsoft since XML is an international and vendor neutral standard. After you create an XML document using methods provided by DataSet, you can parse it in .NET programmatically using the System.Xml.XmlDocument object.

ADO .NET makes it extremely easy to create XML documents. This is the only code you need to create a XML document where the principal customer contact is the owner using the Northwind sample database from Microsoft. Don't worry about all the new and unfamiliar code here ... we'll consider the details of this type of program in future articles.

' Declare the ADO .NET objects
Dim myData As New DataSet()
Dim myXML As String
Dim mySelectQuery As String = _
"SELECT CompanyName FROM Suppliers"
Dim myConnection As New _
OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source={path}\Northwind.mdb")
Dim strSelect As String = _
"SELECT * FROM Customers WHERE ContactTitle = 'Owner'"
Dim dsCmd As _
New OleDbDataAdapter(strSelect, myConnection)
' Fill the DataSet object
dsCmd.Fill(myData, "CustomerOwners")
' Create a text XML document
myData.WriteXml("TestXML.txt")
myConnection.Close()

Friday, October 20, 2006

Material

Tutorial on Video: http://www.box.net/public/riuvdltpzl