Wrox Programmer Forums
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2007, 11:38 PM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old August 11th, 2007, 04:24 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

You have made populate_grid as Function. Change it to Method as:

Public Sub populate_grid(ByVal populate As System.EventArgs)
' Your code goes here
End Sub


Gaurav
 
Old August 12th, 2007, 12:23 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Or, change the function to return a value if that's what you intended.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
reg conn to sql server 2005 from vb.net 2005.. veda SQL Server 2005 2 July 1st, 2008 12:16 AM
Can I run VB .net 2005 with DOT NET 2003 APPLICATI kadesskade BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 August 8th, 2006 05:14 AM
send MASS Emails in ASP.NET 2 with VB.NET 2005 alexdcosta ASP.NET 2.0 Basics 1 July 17th, 2006 12:31 AM
Should I go VB.NET or VB 2005 from VB6? HB Visual Studio 2005 1 December 9th, 2005 03:13 AM
ASP.NET function in VS 2005 B1 boksi Visual Studio 2005 1 April 21st, 2005 07:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.