vb.net 2005 function
can anyone fix this code? it keeps telling me "Function 'populate_grid' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."
Public Function populate_grid(ByVal populate As System.EventArgs)
connect()
cn.Open()
str = "SELECT emp_name,emp_no,designation,phno1,salary,OT FROM Employee ORDER BY emp_no"
str = "SELECT emp_info.emp_no,dept.dept_code,designation.desig,e mp_info.name,emp_info.address FROM emp_info,dept,designation"
str = "SELECT * FROM Employee ORDER BY emp_no"
cmd = New OleDbCommand(str, cn)
adp = New OleDbDataAdapter(cmd)
If reset1 = True Then
dt.Reset()
End If
adp.Fill(dt)
cn.Close()
reset1 = True
grid_emp.DataSource = dt.Tables(0)
End Function
Private Sub lblemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblemp.Click
lblemp.BackColor = Color.Cornsilk
lbllocation.BackColor = Color.BurlyWood
lblvendor.BackColor = Color.BurlyWood
emp_page.Visible = True
Call populate_grid()
Dim tab As New DataTable()
For Each tab In dt.Tables
Dim t As DataGridTableStyle = New DataGridTableStyle()
t.MappingName = tab.TableName
grid_emp.TableStyles.Add(t)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Panel1.BackColor = Color.BurlyWood
cn.Open()
reset1 = False
MessageBox.Show(Application.ExecutablePath)
MessageBox.Show(Application.StartupPath)
MessageBox.Show(Application.CommonAppDataPath)
active = True
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
empedit.txtename.Text = ""
empedit.txtecodenum.Text = ""
Dim last As Integer = dt.Tables(0).Rows.Count - 1
empedit.txtecodenum.Text = dt.Tables(0).Rows(last).Item(1) + 1
empedit.cmbedes.Text = ""
empedit.rdbmale.Checked = False
empedit.rdbfemale.Checked = False
empedit.dtpedob.Text = ""
empedit.cmbebg.Text = ""
empedit.rtxtepadd.Text = ""
empedit.rtxtradd.Text = ""
empedit.txteph1.Text = ""
empedit.txteph2.Text = ""
empedit.txtemobile1.Text = ""
empedit.txtemobile2.Text = ""
empedit.txteemail.Text = ""
empedit.txtedl.Text = ""
empedit.txtepassport.Text = ""
empedit.txtepan.Text = ""
empedit.txtecontact.Text = ""
empedit.txtecontactno.Text = ""
empedit.txtesalary.Text = ""
empedit.txterate.Text = ""
empedit.rtxtcomments.Text = ""
doadd = True
empedit.Show()
End Sub
Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
Dim i As Integer
Dim count As Integer = grid_emp.CurrentRowIndex
Dim count2 As Integer = dt.Tables(0).Rows.Count() - 1
For i = 0 To count
If grid_emp.IsSelected(i) Then
count = i
End If
Next
empedit.txtename.Text = dt.Tables(0).Rows(count).Item(0)
empedit.txtecodenum.Text = dt.Tables(0).Rows(count).Item(1)
empedit.cmbedes.Text = dt.Tables(0).Rows(count).Item(2)
MessageBox.Show(count & " " & empedit.txtecodenum.Text)
Dim gender1 As String = "male"
If dt.Tables(0).Rows(count).Item(3).ToString = gender1 Then
empedit.rdbmale.Checked = True
Else
empedit.rdbfemale.Checked = True
End If
empedit.rdbmale.Checked = dt.Tables(0).Rows(count).Item(4)
empedit.rdbfemale.Checked = dt.Tables(0).Rows(count).Item(5)
empedit.dtpedob.Text = dt.Tables(0).Rows(count).Item(4).ToString
empedit.cmbebg.Text = dt.Tables(0).Rows(count).Item(5)
empedit.rtxtepadd.Text = dt.Tables(0).Rows(count).Item(6)
empedit.rtxtradd.Text = dt.Tables(0).Rows(count).Item(7)
empedit.txteph1.Text = dt.Tables(0).Rows(count).Item(8)
empedit.txteph2.Text = dt.Tables(0).Rows(count).Item(9)
empedit.txtemobile1.Text = dt.Tables(0).Rows(count).Item(10)
empedit.txtemobile2.Text = dt.Tables(0).Rows(count).Item(11)
empedit.txteemail.Text = dt.Tables(0).Rows(count).Item(12)
empedit.txtedl.Text = dt.Tables(0).Rows(count).Item(13)
empedit.txtepassport.Text = dt.Tables(0).Rows(count).Item(14)
empedit.txtepan.Text = dt.Tables(0).Rows(count).Item(15)
empedit.txtecontact.Text = dt.Tables(0).Rows(count).Item(16)
empedit.txtecontactno.Text = dt.Tables(0).Rows(count).Item(17)
empedit.txtesalary.Text = dt.Tables(0).Rows(count).Item(18)
empedit.txterate.Text = dt.Tables(0).Rows(count).Item(19)
empedit.rtxtcomments.Text = dt.Tables(0).Rows(count).Item(20)
doadd = False
empedit.Show()
End Sub
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
If (MessageBox.Show("By Clicking on OK ,This record will be premanantely Deleted,R u sure want ro Delete it ? If yes Click OK ,if No then Click Cancle ", "Delete Operation") = Windows.Forms.DialogResult.OK) Then
Dim emp_no As String
Dim i As Integer = 0
Dim count As Integer
count = grid_emp.CurrentRowIndex()
count = dt.Tables(0).Rows.Count - 1
For i = 0 To count
If grid_emp.IsSelected(i) Then
count = i
MessageBox.Show(i & " " & count)
Exit For
End If
Next
empedit.txtecodenum.Text = dt.Tables(0).Rows(count).Item(1)
emp_no = dt.Tables(0).Rows(count).Item(1).ToString
MessageBox.Show(count & " " & dt.Tables(0).Rows(count).Item(1))
cn.Open()
str = "DELETE FROM Employee WHERE emp_no=" & empedit.txtecodenum.Text
cmd = New OleDbCommand(str, cn)
adp = New OleDbDataAdapter(cmd)
dt.Reset()
adp.Fill(dt)
cn.Close()
MessageBox.Show("Selected Records Deleted")
Call populate_grid()
End If
End Sub
Private Sub lblvendor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblvendor.Click
lblemp.BackColor = Color.BurlyWood
lbllocation.BackColor = Color.BurlyWood
lblvendor.BackColor = Color.Cornsilk
End Sub
Private Sub lbllocation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbllocation.Click
lblemp.BackColor = Color.BurlyWood
lbllocation.BackColor = Color.Cornsilk
lblvendor.BackColor = Color.BurlyWood
End Sub
Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
cn.Open()
str = "SELECT * FROM Employee WHERE emp_name LIKE '" & txtsearch.Text & "%'"
str = "SELECT emp_name,emp_no,designation,phno1,salary,O/T FROM Employee WHERE emp_name LIKE '" & txtsearch.Text & "%'"
str = "SELECT emp_info.emp_no,dept.dept_code,designation.desig,e mp_info.name,emp_info.address FROM emp_info,dept,designation"
cmd = New OleDbCommand(str, cn)
dt.Reset()
adp = New OleDbDataAdapter(cmd)
adp.Fill(dt)
cn.Close()
grid_emp.DataSource = dt.Tables(0)
End Sub
Private Sub Employee_information_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
If active = False Then
Call populate_grid()
grid_emp.DataSource = dt.Tables(0)
End If
active = False
End Sub
End Class
|