‘Create the button
Dim btn As New Button()
‘Specify the location and the size
btn.Location = New System.Drawing.Point(200, 30)
btn.Size = New System.Drawing.Size(100, 20)
btn.Text = “New Button”
‘Add it to the forms control collection
Me.Controls.Add(btn)
‘Link the event to the event handler
AddHandler btn.Click, AddressOf Me.ClickButton
Archive for the ‘VB.NET’ Category
Create a button run time
Posted in VB.NET, tagged vb.net on January 7, 2008 | Comments Off
DataBind with RadioButtonList in VB.NET
Posted in VB.NET, tagged vb.net on October 9, 2006 | Leave a Comment »
white these code to page_load so Radio Button List will be generated
Dim strConnection As String = “data source=(local);initial catalog=testDB; user id=sa; password=1234;”
Dim strSQLforListBox As String = “SELECT distinct FirstName, ID “
strSQLforListBox += “FROM Users”
Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New SqlCommand(strSQLforListBox, objConnection)
objConnection.Open()
radEmployees.DataSource = objCommand.ExecuteReader()
radEmployees.DataTextField = “FirstName”
radEmployees.DataValueField = “ID”
radEmployees.DataBind()
objConnection.Close()
Then we need to write the following [...]
SqlConnection in VB.NET
Posted in VB.NET, tagged vb.net on October 9, 2006 | Leave a Comment »
Dim strConnection As String = “data source=(local);initial catalog=testDB; user id=sa; password=1234;”
Dim objConnection As New SqlConnection(strConnection)
Dim strSQL As String = “SELECT * from tblTest;”
Dim objCommand As New SqlCommand(strSQL, objConnection)
objConnection.Open()
Response.Write(“ServerVersion: ” & objConnection.ServerVersion & _
vbCrLf & “Datasource: ” & objConnection.DataSource & _
vbCrLf & “Database: ” & objConnection.Database)
DataGrid1.DataSource = objCommand.ExecuteReader()
DataGrid1.DataBind()
objConnection.Close()
request response in vb .net
Posted in VB.NET, tagged vb.net on October 9, 2006 | Leave a Comment »
response goes like that
Response.Cookies(“name”).Value = TextBox1.TextResponse.Cookies(“pass”).Value = TextBox2.Text
Response.Redirect(“newForm.aspx”)
Request takes such way
Label1.Text = Request.Cookies(“name”).Value & ” ” & Request.Cookies(“pass”).Value
XML Reader in VB.NET
Posted in VB.NET, tagged vb.net on August 8, 2006 | Leave a Comment »
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReadXMLFromFile()
End Sub
Private Sub ReadXMLFromFile()
Dim reader As New XmlTextReader(“c:dom.xml”)
Dim contents As String = “”
While reader.Read()
reader.MoveToContent()
If reader.NodeType = XmlNodeType.Element Then
contents &= reader.Name & “: “
End If
If reader.NodeType = XmlNodeType.Text Then
contents &= reader.Value & ControlChars.CrLf
End If
End While
TextBox1.Text = contents
End Sub
Insert Data in MSAccess (OleDb data Provider)
Posted in VB.NET, tagged vb.net on July 18, 2006 | 3 Comments »
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim cmd As OleDb.OleDbCommand
Dim icount As Integer
Dim conn As OleDb.OleDbConnection
Try
conn = GetConnection()
conn.Open()
str = “insert into address values(” & CInt(TextBox1.Text) & “,’” & TextBox2.Text & “‘,’” & TextBox3.Text & “‘,’” & TextBox4.Text & “‘,’” & TextBox5.Text & “‘)”
’string stores the [...]
Data Access using MSAccess (OleDb data Provider)
Posted in VB.NET, tagged vb.net on July 18, 2006 | Leave a Comment »
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As OleDb.OleDbConnection = GetConnection()
Dim ds As New DataSet
Dim sql As String = “select * from address”
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
da.Fill(ds, “address”)
DataGrid1.DataSource = ds.Tables(“address”)
End Sub
Public Function GetConnection() As OleDb.OleDbConnection
‘return a new connection to the database
Return New OleDb.OleDbConnection(“Provider=Microsoft.Jet.OleDb.4.0;data source=C:test.mdb;”)
End Function
read text file in vb.net
Posted in VB.NET, tagged vb.net on July 17, 2006 | 5 Comments »
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim LineIn As String
oRead = oFile.OpenText(“C:sample.txt”)
While oRead.Peek -1
LineIn &= oRead.ReadLine()
End While
RichTextBox1.Text = LineIn
oRead.Close()
read a text file in vb.net
Posted in VB.NET, tagged vb.net on July 17, 2006 | Leave a Comment »
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim LineIn As String
oRead = oFile.OpenText(“C:sample.txt”)
While oRead.Peek <> -1
LineIn &= oRead.ReadLine()
End While
RichTextBox1.Text = LineIn
oRead.Close()
write text file in vb.net
Posted in VB.NET, tagged vb.net on July 17, 2006 | 1 Comment »
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
oWrite = oFile.CreateText(“C:sample.txt”)
oWrite.WriteLine(“Write a line to the file”)
oWrite.WriteLine()
oWrite.Close()

