Winforms Prgs

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Winforms Prgs as PDF for free.

More details

  • Words: 3,912
  • Pages: 40
 PROGRAM ON RADIOBUTTON CONTROL

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ctrl1, ctrl2, ctrl3 As Control Dim rb1, rb2, rb3 As RadioButton Dim d1, m1, y1 As String For Each ctrl1 In Me.GroupBox1.Controls If TypeOf ctrl1 Is RadioButton Then rb1 = CType(ctrl1, RadioButton) If rb1.Checked = True Then Label1.Text = _ Format(System.DateTime.Today, rb1.Text & "/MM/yyyy") d1 = rb1.Text End If End If Next For Each ctrl2 In Me.GroupBox2.Controls If TypeOf ctrl2 Is RadioButton Then rb2 = CType(ctrl2, RadioButton) If rb2.Checked = True Then Label1.Text = Format(System.DateTime.Today, d1 & "/" & rb2.Text & "/yyyy") m1 = rb2.Text End If

End If Next For Each ctrl3 In Me.GroupBox3.Controls If TypeOf ctrl3 Is RadioButton Then rb3 = CType(ctrl3, RadioButton) If rb3.Checked = True Then y1 = rb3.Text Label1.Text = Format(System.DateTime.Today, d1 & "/" & m1 & "/" & rb3.Text) End If End If Next End Sub  PROGRAM ON LISTVIEW CONTROL

Dim addflag As Boolean = False Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListView1.Columns.Add("First", _ ListView1.Width / 4, HorizontalAlignment.Left) ListView1.Columns.Add("Second", _ ListView1.Width / 4, HorizontalAlignment.Left) ListView1.Columns.Add("Third", _ ListView1.Width / 4, HorizontalAlignment.Left) ListView1.Columns.Add("Fourth", ListView1.Width / 4, _ HorizontalAlignment.Left) ListView1.Items.Add("ITEM 1", 0) ListView1.Items.Add("ITEM 2", 0) ListView1.Items.Add("ITEM 3", 0) ListView1.Items(0).SubItems.Add("AAA") ListView1.Items(0).SubItems.Add("BBB") ListView1.Items(0).SubItems.Add("CCC") ListView1.Items(1).SubItems.Add("AAA") ListView1.Items(1).SubItems.Add("BBB") ListView1.Items(1).SubItems.Add("CCC") ListView1.Items(2).SubItems.Add("AAA") ListView1.Items(2).SubItems.Add("BBB") ListView1.Items(2).SubItems.Add("CCC") ListView1.LargeImageList = ImageList1 ListView1.SmallImageList = ImageList2 ComboBox1.Items.AddRange(New Object() _ {"Large Icon", "Details", "Small Icon", "List"})

ComboBox1.SelectedIndex = 0 ComboBox1.DropDownStyle = _ ComboBoxStyle.DropDownList ListView1.View = ComboBox1.SelectedIndex

ListView1.FullRowSelect = True End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged ListView1.View = ComboBox1.SelectedIndex End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListView1.CheckBoxes = Not ListView1.CheckBoxes End Sub Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck If e.NewValue = CheckState.Checked Then Label1.Text = "CheckBox " & e.Index + 1 & _ " Checked" Else Label1.Text = "CheckBox " & e.Index + 1 & _ " Not Checked" End If End Sub Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick Dim i, j As Integer i = 0 j = Not i Me.Text = i & " - j" & j End Sub End Class  PROGRAM ON CHECKED LISTBOX CONTROL

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click CheckedListBox1.Items.Clear() CheckedListBox1.Items.AddRange _ (New Object() _ {"Sam", "Ravi", "Sameer", "Rohan", "Rahul", "Sohan"}) CheckedListBox1.CheckOnClick = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer ComboBox1.Items.Clear() For i = 0 To CheckedListBox1.Items.Count - 1 If CheckedListBox1.GetItemChecked(i) = True Then ComboBox1.Items.Add _ (CheckedListBox1.Items(i).ToString) End If Next End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim i, j, cnt As Integer Dim str As String cnt = CheckedListBox1.Items.Count - 1 For i = cnt To 0 Step -1

For j = 0 To i If CheckedListBox1.GetItemChecked(i) = True Then

CheckedListBox1.Items.Remove _ (CheckedListBox1.Items(i).ToString) Exit For str = CheckedListBox1.Items(i).ToString End If Next Next End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ComboBox1.Items.Clear() End Sub End Class  PROGRAM ON TREEVIEW CONTROL

Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim mgr() As String = {"PAVAN", "SAMEER", "DEEPTHI"} Dim emp1() As String = {"raman", "sagar"} Dim i, j, k As Integer

i = emp1.Length Dim STR As String For k = 0 To mgr.Length - 1 TreeView1.Nodes.Add(mgr(k)) If k = 0 Then For Each STR In emp1 TreeView1.Nodes(k).Nodes.Add(STR) Next End If Next End Sub Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect Me.Text = e.Node.Text End Sub End Class  PROGRAM ON HORIZONTAL SCROLL USING TIMER CONTROL

Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load HScrollBar1.Minimum = 1 HScrollBar1.Maximum = 1000 HScrollBar1.Value = 1 End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Label1.Text = "Hello Friends" HScrollBar1.Value += 1 If HScrollBar1.Value = HScrollBar1.Maximum Then Timer1.Enabled = False Label2.Text = HScrollBar1.Value Else Timer1.Interval = HScrollBar1.Value Label1.Visible = Not Label1.Visible Label2.Text = HScrollBar1.Value End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub End Class  PROGRAM ON IMAGELIST AND OPEN FILE DIALOG BOX CONTROL

Dim img As Integer = 0 Private Sub CMDOPEN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDOPEN.Click OpenFileDialog1.Filter = _ "gif (*.gif)|*.gif|jpeg (*.jpg)|*.jpg" If OpenFileDialog1.ShowDialog = DialogResult.OK Then If Not (OpenFileDialog1.FileNames Is Nothing) Then Dim n As Integer For n = 0 To OpenFileDialog1.FileNames.Length - 1 Me.ActiveForm.Text = n ImageList1.Images.Add(Image.FromFil e(OpenFileDialog1.FileNames(n))) Next Else ImageList1.Images.Add(Image.FromFile(Op enFileDialog1.FileNames(OpenFileDialog1.FileName))) End If End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click PictureBox1.Image = ImageList1.Images(img) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If img <= ImageList1.Images.Count - 1 Then Me.Text = img PictureBox1.Image = ImageList1.Images(img) img += 1 Else img = 0 End If End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Static img1 As Integer = ImageList1.Images.Count - 1 If img1 >= 0 Then Me.Text = img1 PictureBox1.Image = ImageList1.Images(img1) img1 -= 1 Else img1 = ImageList1.Images.Count - 1 End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim i As Integer = ImageList1.Images.Count - 1 PictureBox1.Image = ImageList1.Images(i) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Image = ImageList1.Images(0) End Sub End Class  PROGRAM ON FORM LEVEL VALIDATION

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() Dim ctrl As Control Dim str As String For Each ctrl In Me.Controls str = Convert.ToString(ctrl.GetType()) ListBox1.Items.Add(str) If str = "System.Windows.Forms.TextBox" Then If Trim(ctrl.Text) = "" Then MsgBox("Cann't make null values") ctrl.Focus() End If ElseIf str = "System.Windows.Forms.ComboBox" Then If ctrl.Text = "State" Then MsgBox("Select A State name") ctrl.Focus() End If End If Next Dim i As Integer = 0 For Each ctrl In GroupBox1.Controls If TypeOf ctrl Is RadioButton = True Then

Dim rb As RadioButton = _ CType(ctrl, RadioButton) If rb.Checked = True Then ListBox1.Items.Add(rb.Text) i += 1 Me.Text = i If i = 1 Then Exit Sub Else MsgBox("Select one option") End If End If End If Next End Sub Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With ComboBox1.Items .Add("Cities") .Add("Delhi") .Add("Banglore") .Add("Hyderabad") End With ComboBox1.SelectedIndex = 0 End Sub End Class

DATABASE PROGRAMS  DATABASE CONNECTIVITY CONNCTION

WITH

SQL

SERVER

USING

ADODB

Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn = New ADODB.Connection cn.ConnectionString = "provider=sqloledb;uid=sa;database=railway" cn.Open() rs = New ADODB.Recordset rs.Open("train_details", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) While Not rs.EOF = True ListBox1.Items.Add(rs.Fields(0).Value) rs.MoveNext() End While rs.MoveFirst() display() End Sub Private Sub display() TextBox1.Text = rs.Fields(0).Value TextBox2.Text = rs.Fields("t_name").Value TextBox3.Text = rs.Fields(2).Value TextBox4.Text = rs.Fields(3).Value TextBox5.Text = rs.Fields(4).Value TextBox6.Text = rs.Fields(5).Value

End Sub Private Sub cmdmovef_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdmovef.Click rs.MoveFirst() display() StatusBar1.Panels(0).Text = "U are at first record" End Sub Private Sub cmdprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprev.Click rs.MovePrevious() If rs.BOF = True Then StatusBar1.Panels(0).Text = "U are at first record" rs.MoveFirst() End If display() End Sub Private Sub cmdnxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnxt.Click rs.MoveNext() If rs.EOF = True Then StatusBar1.Panels(0).Text = "U are at last record" rs.MoveLast() End If display() End Sub Private Sub cmdlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlast.Click rs.MoveLast() StatusBar1.Panels(0).Text = "U are at last record" display() End Sub

Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click rs.AddNew() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox1.Focus() End Sub Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click rs.Fields(0).Value = Val(TextBox1.Text) rs.Fields(1).Value = TextBox2.Text rs.Fields(2).Value = TextBox3.Text rs.Fields(3).Value = TextBox4.Text rs.Fields(4).Value = Val(TextBox5.Text) rs.Fields(5).Value = Val(TextBox6.Text) rs.Save() End Sub Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click rs.Fields(0).Value = Val(TextBox1.Text) rs.Fields(1).Value = TextBox2.Text rs.Fields(2).Value = TextBox3.Text rs.Fields(3).Value = TextBox4.Text rs.Fields(4).Value = Val(TextBox5.Text) rs.Fields(5).Value = Val(TextBox6.Text) rs.Update() End Sub Private Sub cmddel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddel.Click Dim ans As DialogResult ans = MessageBox.Show("Are u sure to delete the current record ?", "Record Delete Confirmation ",

MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then rs.Delete() rs.MoveNext() If rs.EOF = True Then StatusBar1.Panels(0).Text = "U are at last record" rs.MoveLast() End If display() End If End Sub Private Sub cmdsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsearch.Click rs.MoveFirst() rs.Find("train_no = " & Trim(TextBox7.Text) & " ", 0, ADODB.SearchDirectionEnum.adSearchForward) If rs.EOF = True Then StatusBar1.Panels(0).Text = "Train No " & TextBox7.Text & " Not Found" TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" Exit Sub End If display() End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged rs.MoveFirst() rs.Find("train_no = " & Trim(ListBox1.SelectedItem) & " ", 0, ADODB.SearchDirectionEnum.adSearchForward)

display() End Sub  DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING SQL CLIENT AND DATA ADAPTER OBJECTS WITH DATASET

Imports System.Data Imports System.Data.SqlClient Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cn As New SqlConnection("server=ecas;uid=sa;pwd=;database=railway ") Dim adp As New SqlDataAdapter("select * from emp", cn) Dim ds As New DataSet adp.Fill(ds, "emp") DataGrid1.ReadOnly = True DataGrid1.DataSource = ds.Tables("emp") End Sub  DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING OLEDB PROVIDERS AND DATA ADAPTER OBJECTS WITH DATASET

Imports System.Data Imports System.Data.OleDb Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Dim cn As New OleDbConnection("provider=sqloledb;data source=ecas;uid=sa;initial catalog=railway") 'for server connectivity Dim cn As New OleDbConnection("provider=sqloledb;uid=sa;initial catalog=railway") Dim adp As New OleDbDataAdapter("select * from emp", cn) Dim ds As New DataSet adp.Fill(ds) DataGrid1.DataSource = ds.Tables(0) End Sub

 DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING MS ACCESS 2000 AND DATA ADAPTER OBJECTS WITH DATASET

Imports System.Data.OleDb Imports System.Data Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:\test.mdb") 'Provider=MSDAORA.1;User ID=scott;Data Source=oracle8i Dim adp As New OleDbDataAdapter("select * from employee", cn) Dim ds As New DataSet adp.Fill(ds) DataGrid1.DataSource = ds.Tables(0) End Sub

 DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING ODBC CONNECTION WITH SQL SERVER AND DATA ADAPTER OBJECTS WITH DATASET

Imports Imports Private ByVal e

System.Data System.Data.Odbc Sub Form5_Load(ByVal sender As System.Object, As System.EventArgs) Handles MyBase.Load Dim cn As New OdbcConnection("dsn=test;uid=sa") Dim adp As New OdbcDataAdapter("select * from emp", cn) Dim ds As New DataSet adp.Fill(ds) DataGrid1.DataSource = ds.Tables(0) End Sub  DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING SQL CLIENT AND DATAVIEW OBJECTS WITH DATASET

Imports System.Data Imports System.Data.OleDb Dim cn As New OleDbConnection("provider=sqloledb;uid=sa;database=nort hwind") Dim adp As New OleDbDataAdapter("select * from customers", cn) Dim ds As New DataSet Dim dv As DataView Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load adp.Fill(ds) DataGrid1.DataSource = ds.Tables(0) End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged dv = New DataView(ds.Tables(0)) dv.Sort = "companyname desc" dv.RowFilter = "companyname like '" & Trim(TextBox1.Text) & "%' " DataGrid1.DataSource = dv End Sub

 DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING ODBC USING SQL SERVER TO PERFORM RECORD NAVIGATION, INSERT, UPDATE, DELETE, SEARCH AND RECORD COUNT FUNCTIONS

Imports System.Data Imports System.Data.Odbc Dim cn As New OdbcConnection("dsn=test;uid=sa") Dim i As Integer Dim ds As New DataSet Dim adp As New OdbcDataAdapter("select * from emp", cn) Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load display2() showeno() display() End Sub Private Sub display() TextBox1.Text = ds.Tables("emp").Rows(i)(0) TextBox2.Text = ds.Tables("emp").Rows(i)(1) TextBox3.Text = ds.Tables("emp").Rows(i)(2) TextBox4.Text = ds.Tables("emp").Rows(i)(3) ComboBox1.Text = ds.Tables("emp").Rows(i)(4)

TextBox5.Text = ds.Tables("emp").Rows(i)(5) TextBox6.Text = ds.Tables("emp").Rows(i)(6) Label8.Text = "Records " & i + 1 & "/" & ds.Tables("emp").Rows.Count End Sub Private Sub display2() Dim cmd As New OdbcCommand("select * from emp", cn) Dim dr As OdbcDataReader cn.Open() dr = cmd.ExecuteReader dr.Read() TextBox1.Text = dr.Item(0) TextBox2.Text = dr.Item(1) TextBox3.Text = dr.Item(2) TextBox4.Text = dr.Item(3) ComboBox1.Text = dr.Item(4) TextBox5.Text = dr.Item("exp") TextBox6.Text = dr.Item(6) cn.Close() adp.Fill(ds, "emp") End Sub Private Sub cmdfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdfirst.Click i = 0 display() End Sub Private Sub cmdprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprev.Click i -= 1 If i < 0 Then i += 1 Else display() End If End Sub

Private Sub cmdnxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnxt.Click i += 1 If i > ds.Tables("emp").Rows.Count - 1 Then i -= 1 Else display() End If End Sub Private Sub cmdlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlast.Click i = ds.Tables("emp").Rows.Count - 1 display() End Sub Private Sub cmdclr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdclr.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" ComboBox1.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox1.Focus() disp() End Sub Private Sub disp() Dim cmd As New OdbcCommand cmd.CommandText = "select deptno from dept" cmd.Connection = cn Dim dr As OdbcDataReader cn.Open() dr = cmd.ExecuteReader While dr.Read ComboBox1.Items.Add(dr.Item(0)) End While cn.Close()

End Sub Private Sub cmdinsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdinsert.Click Dim cmd1 As New OdbcCommand cmd1.CommandText = "select max(eno) from emp" cmd1.Connection = cn Dim str1 As String cn.Open() str1 = cmd1.ExecuteScalar cn.Close() MsgBox(str1.Substring(0, str1.IndexOf(0))) Dim l As Integer 'l = Len(str1) Dim str As String str = "insert into emp values('" & Trim(TextBox1.Text) & "', '" & Trim(TextBox2.Text) & "','" & Trim(TextBox3.Text) & "','" & Trim(TextBox4.Text) & "'," & ComboBox1.SelectedItem & "," & Trim(TextBox5.Text) & "," & Trim(TextBox6.Text) & ") " Dim cmd As New OdbcCommand(str, cn) Dim ans As DialogResult ans = MessageBox.Show("Are u sure to add new record?", "New Record Confirmation Box", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then cn.Open() 'cmd.ExecuteNonQuery() cn.Close() End If display2() End Sub Private Sub showeno() Dim cmd As New OdbcCommand cmd.CommandText = "select eno from emp" cmd.Connection = cn Dim dr As OdbcDataReader

cn.Open() dr = cmd.ExecuteReader While dr.Read ComboBox2.Items.Add(dr.Item(0)) End While cn.Close() End Sub Private Sub enosearch() Dim cmd As New OdbcCommand("select * from emp where eno = '" + ComboBox2.SelectedItem + "' ", cn) Dim dr As OdbcDataReader cn.Open() dr = cmd.ExecuteReader dr.Read() TextBox1.Text = dr.Item(0) TextBox2.Text = dr.Item(1) TextBox3.Text = dr.Item(2) TextBox4.Text = dr.Item(3) ComboBox1.Text = dr.Item(4) TextBox5.Text = dr.Item("exp") TextBox6.Text = dr.Item(6) cn.Close() End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged enosearch() End Sub Private Sub cmdmodify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdmodify.Click Dim str As String str = "update emp set ename='" & Trim(TextBox2.Text) & "',addr='" & Trim(TextBox3.Text) & "',desig='" & Trim(TextBox4.Text) & "',deptno = " & ComboBox1.Text & ",exp=" & Trim(TextBox5.Text) & ",salary=" & Trim(TextBox6.Text) & " where eno = '" & ComboBox2.SelectedItem & "' " 'cmd.CommandText = "update emp set ename='" & Trim(TextBox2.Text) & "',addr='" & Trim(TextBox3.Text)

& "',desig='" & Trim(TextBox4.Text) & "',deptno = " & ComboBox1.Text & ",exp=" & Trim(TextBox5.Text) & ",salary=" & Trim(TextBox6.Text) & " where eno = '" & ComboBox2.SelectedItem & "' " Dim cmd As New OdbcCommand(str, cn) 'cmd.Connection = cn Dim ans As DialogResult ans = MessageBox.Show("Are u sure to modify this record?", "Record Modify Confirmation Box", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then cn.Open() MsgBox(cmd.CommandText) cmd.ExecuteNonQuery() cn.Close() End If display2() End Sub Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click Dim cmd As New OdbcCommand cmd.CommandText = "delete from emp where eno = '" & TextBox1.Text & "' " cmd.Connection = cn Dim ans As DialogResult ans = MessageBox.Show("Are u sure to delete this record?", "Record Delete Confirmation Box", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then cn.Open() cmd.ExecuteNonQuery() cn.Close() End If display2() End Sub

 DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING OLEDB USING SQL SERVER TO PERFORM RECORD NAVIGATION, INSERT, UPDATE, DELETE, SEARCH AND RECORD COUNT FUNCTIONS USING TREEVIEW AND LISTVIEW CONTROL

Imports System.Data Imports System.Data.OleDb Dim cn, cn2 As New OleDbConnection Dim cn3 As New OleDbConnection("provider=sqloledb;uid=sa;database=muse r") Dim adp5 As New OleDbDataAdapter("select * from uaccount", cn3) Dim ds5 As New DataSet Dim i As Integer = 0

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn = myconn() Dim cmd As New OleDbCommand("select distinct con from uaccount", cn) Dim dr As OleDbDataReader cn.Open() dr = cmd.ExecuteReader While dr.Read TreeView1.Nodes.Add(dr.Item(0)) End While cn.Close() adp5.Fill(ds5) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListView1.Items.Clear() ListView1.Columns.Clear() cn = myconn() cn2 = myconn() Dim adp As New OleDbDataAdapter("select * from uaccount", cn) Dim ds As New DataSet adp.Fill(ds, "uaccount") Dim i As Integer For i = 0 To ds.Tables(0).Columns.Count - 1 ListView1.Columns.Add(ds.Tables(0).Columns( i).ColumnName, ListView1.Width / 5, HorizontalAlignment.Left) Next ListView1.View = View.Details Dim cmd2 As New OleDbCommand cmd2.CommandText = "select count(*) from uaccount where con = '" & TreeView1.SelectedNode.Text & "' " Dim dr2 As OleDbDataReader

Dim j, cnt2 As Integer j = 0 Dim cmd As New OleDbCommand cmd.CommandText = "select * from uaccount where con = '" & TreeView1.SelectedNode.Text & "' " cmd.Connection = cn Dim dr1 As OleDbDataReader Try

.Item(1)) .Item(2)) .Item(3)) .Item(4))

cmd2.Connection = cn2 cn2.Open() cnt2 = CInt(cmd2.ExecuteScalar) cn2.Close() cn.Open() dr1 = cmd.ExecuteReader While j < cnt2 While dr1.Read ListView1.Items.Add(dr1.Item(0)) ListView1.Items(j).SubItems.Add(dr1 ListView1.Items(j).SubItems.Add(dr1 ListView1.Items(j).SubItems.Add(dr1 ListView1.Items(j).SubItems.Add(dr1

j += 1 End While End While Catch MsgBox(cmd.CommandText) End Try cn.Close() ListView1.FullRowSelect = True End Sub Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged Dim str As String str = ListView1.FocusedItem.Text

Dim cmd As New OleDbCommand cn = myconn() cmd.CommandText = "select * from uaccount where slno = " & str cmd.Connection = cn Dim dr As OleDbDataReader cn.Open() dr = cmd.ExecuteReader dr.Read() TextBox1.Text = dr.Item(0) TextBox2.Text = dr.Item(1) TextBox3.Text = dr.Item(2) TextBox4.Text = dr.Item(3) TextBox5.Text = dr.Item(4) cn.Close() 'display() End Sub Private Sub display() TextBox1.Text = ds5.Tables(0).Rows(i)(0) TextBox2.Text = ds5.Tables(0).Rows(i)(1) TextBox3.Text = ds5.Tables(0).Rows(i)(2) TextBox4.Text = ds5.Tables(0).Rows(i)(3) TextBox5.Text = ds5.Tables(0).Rows(i)(4) End Sub Private Sub CMDFIRST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDFIRST.Click i = 0 display() End Sub Private Sub CMDPREV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDPREV.Click i -= 1 If i < 0 Then i += 1 Else display()

End If End Sub Private Sub CMDNEXT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDNEXT.Click i += 1 If i > ds5.Tables(0).Rows.Count - 1 Then i -= 1 Else display() End If End Sub Private Sub CMDLAST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDLAST.Click i = ds5.Tables(0).Rows.Count - 1 display() End Sub Private Sub CMDADDNEW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDADDNEW.Click cn = myconn() Dim cmd1 As New OleDbCommand cmd1.CommandText = "select max(slno) from uaccount" cmd1.Connection = cn Dim sno As Integer cn.Open() sno = cmd1.ExecuteScalar cn.Close() sno += 1 TextBox1.Text = sno Dim cmd As New OleDbCommand cmd.CommandText = _ "insert into uaccount values(" & Trim(Val(TextBox1.Text)) & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & Val(TextBox4.Text) & ",'" & TextBox5.Text & "')" cmd.Connection = cn

Dim ans As DialogResult ans = MessageBox.Show("Are u sure to insert new record ?", "Add new Record confirmation box", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If ans = DialogResult.Yes Then cn.Open() cmd.ExecuteNonQuery() cn.Close() End If End Sub Private Sub CMDCLR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDCLR.Click TextBox1.ReadOnly = True TextBox2.Clear() TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox2.Focus() End Sub Private Sub CMDUPDATE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDUPDATE.Click cn = myconn() Dim cmd As New OleDbCommand cmd.CommandText = "update uaccount set name= '" & Trim(TextBox2.Text) & "',addr = '" & Trim(TextBox3.Text) & "',mobno=" & Trim(Val(TextBox4.Text)) & ",con='" & Trim(TextBox5.Text) & "' where slno = " & Trim(Val(TextBox1.Text)) & " " cmd.Connection = cn Dim ans As DialogResult ans = MessageBox.Show("Are u sure to update the record ?", "Add new Record confirmation box", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If ans = DialogResult.Yes Then cn.Open()

cmd.ExecuteNonQuery() cn.Close() End If End Sub Private Sub CMDDELETE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDDELETE.Click cn = myconn() Dim str As String str = "delete from uaccount where slno = " & Trim(Val(TextBox1.Text)) & " " Dim cmd As New OleDbCommand(str, cn) Dim ans As DialogResult ans = MessageBox.Show("Are u sure to delete the record ?", "Add new Record confirmation box", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If ans = DialogResult.Yes Then cn.Open() cmd.ExecuteNonQuery() cn.Close() End If End Sub

 DATABASE CONNECTIVITY ON ADO.NET CONCEPT USING OLEDB USING SQL SERVER TO PERFORM RECORD INSERT, UPDATE, DELETE USING COMMAND BUILDER OBJECT.

Imports System.Data Imports System.Data.OleDb Dim cn As New OleDbConnection("provider=sqloledb;uid=sa;database=muse r") Dim adp As New OleDbDataAdapter("select * from uaccount", cn) Dim ds As New DataSet Dim dv As New DataView Dim scb As New OleDbCommandBuilder Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load adp.Fill(ds) dv = New DataView(ds.Tables(0))

DataGrid1.DataSource = dv dv.AllowNew = False DataGrid1.ReadOnly = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ans As DialogResult ans = MessageBox.Show("Are u sure to add new record ?", "Add new record ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then dv.AllowNew = True DataGrid1.ReadOnly = False scb = New OleDbCommandBuilder(adp) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ans As DialogResult ans = MessageBox.Show("Are u sure to update the record ?", "Add new record ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification) If ans = DialogResult.Yes Then scb = New OleDbCommandBuilder(adp) adp.Update(ds) End If dv.AllowNew = False DataGrid1.ReadOnly = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click DataGrid1.ReadOnly = False End Sub

 PROGRAM TO DISPLAY ALL THE TABLES OF A SQL SERVER DATABASE i.e. NORTHWIND IN A LISTBOX AND DISPLAY ALL THE RECORDS OF A SELECTED TABLE IN DATAGRID AS WELL AS TO DISPLAY THE AUTOMATED CREATED SQL QUERY IN THE TEXTBOX.

Imports System.Data.OleDb Imports System.Data Dim cn As New OleDbConnection("provider=sqloledb;uid=sa;database=nort hwind") Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text = "" TextBox1.Text = "SELECT * FROM " & ListBox1.SelectedItem

End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim cmd As New OleDbCommand cmd.CommandText = "SELECT * FROM " & ListBox1.SelectedItem cmd.Connection = cn Dim adp As New OleDbDataAdapter adp.SelectCommand = cmd Dim ds As New DataSet Try adp.Fill(ds, "abc") Catch e1 As System.Exception MsgBox(e1.Message) End Try DataGrid1.DataSource = ds.Tables(0) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim cmd As New OleDbCommand cmd.CommandText = "select * from sysobjects where xtype='u'" cmd.Connection = cn Dim dr As OleDbDataReader cn.Open() dr = cmd.ExecuteReader() While dr.Read ListBox1.Items.Add(dr(0)) End While dr.Close() cn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cmd As New OleDbCommand Dim str As String str = " " & TextBox1.Text & " "

cmd.CommandText = str Me.Text = "& str &" cmd.Connection = cn Dim adp As New OleDbDataAdapter adp.SelectCommand = cmd Dim ds As New DataSet Try adp.Fill(ds, "abc") DataGrid1.DataSource = ds.Tables(0) Catch e1 As System.Exception MsgBox(e1.Message) End Try End Sub  PROGRAM ON TO CREATE A CRYSTAL REPORT ON A GIVEN VALUE PASSED BY USER WHILE RUNTIME i.e. pull model crystal report

Imports CrystalDecisions.Shared Imports CrystalDecisions.CrystalReports.Engine Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim rpt As New CrystalReport2 Dim pfc As New ParameterFields Dim pf As New ParameterField Dim dv As New ParameterDiscreteValue pf.ParameterFieldName = "con" dv.Value = InputBox("Enter an connection name no: ") pf.CurrentValues.Add(dv) pfc.Add(pf) CrystalReportViewer1.ParameterFieldInfo = pfc CrystalReportViewer1.SelectionFormula = _ "{uaccount.con}={?con}" CrystalReportViewer1.ReportSource = rpt End Sub

Related Documents

Winforms Prgs
November 2019 5
Reference Prgs
July 2020 4
05 - Winforms
June 2020 3
Anorexie , 4 Prgs
April 2020 15