Feeds:
Posts
Comments

Archive for the ‘VB.NET’ Category

Create a button run time

‘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

Read Full Post »

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 codes in SelectedIndexChanged

Dim strConnection As String = “data source=(local);initial catalog=testDB; user id=sa; password=1234;”

Dim strSQLforGrid As String = “SELECT “
strSQLforGrid += ” FirstName, LastName, “
strSQLforGrid += “phone, PermanentAddress1 “
strSQLforGrid += “FROM Users “
strSQLforGrid += “WHERE ID= ” & radEmployees.SelectedItem.Value

Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New SqlCommand(strSQLforGrid, objConnection)

objConnection.Open()
DataGrid1.DataSource = objCommand.ExecuteReader()
DataGrid1.DataBind()
objConnection.Close()

Read Full Post »

SqlConnection in VB.NET

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()

Read Full Post »

request response in vb .net

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

Read Full Post »

XML Reader in VB.NET

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

Read Full Post »

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 command and CInt is used to convert number to string
        cmd = New OleDb.OleDbCommand(str, conn)
        icount = cmd.ExecuteNonQuery
        MessageBox.Show(“No of row inserted:” & icount)
Catch ex As Exception
        MsgBox(“Exception from insert:” & ex.ToString())
End Try
conn.Close()
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 Full Post »

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 Full Post »

Older Posts »