Hi guys,

The codes below is running perfectly fine.

But I have a problem - if there are no records found in the database, my dropdownlist will not display nothing.

However, I want it to display something like "no records found" instead of havng it blank

Can someone tell me where should I place it to get the results i wanted?
Here are my codes.

InvoiceFunctions.class

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class InvoiceFunctions
Private strConnectionString As String
Private objDataAdapter As SqlDataAdapter
Private objInsertCommand As SqlCommand
Private objLoadCommand As SqlCommand
Private objUpdateCommand As SqlCommand
Private objValidCommand As SqlCommand
Private objDeleteCommand As SqlCommand

Public Sub New()

MyBase.New()

objDataAdapter = New SqlDataAdapter

strConnectionString = ConfigurationManager.ConnectionStrings("Echino").C onnectionString

End Sub
Public Function GetInvoice() As DataSet

Dim query As String = "select * from Invoice"
Dim cmd As New SqlCommand(query)

Return FillDataSet(cmd, "invoice")
End Function

Private Function FillDataSet(ByVal cmd As SqlCommand, ByVal tableName As String) As DataSet
Dim con As New SqlConnection(strConnectionString)
cmd.Connection = con

Dim adapter As New SqlDataAdapter(cmd)

Dim ds As New DataSet()
Try
con.Open()
adapter.Fill(ds, tableName)

Catch ex As Exception
Finally
con.Close()
End Try

Return ds

End Function

AddJobOrder.aspx.vb

Imports [Class]
Imports System.Configuration
Imports System.Data.SqlClient
Partial Public Class AddJobOrder
Inherits System.Web.UI.Page

Dim inv As New InvoiceFunctions

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then

ddl_Invoice.DataSource = inv.GetInvoice
ddl_Invoice.DataTextField = "invoiceNo"
ddl_Invoice.DataValueField = "invoiceNo"
ddl_Invoice.DataBind()

End if
End Sub

End Class
ddl_Invoice.DataSource = inv.GetInvoice
ddl_Invoice.DataTextField = "invoiceNo"
ddl_Invoice.DataValueField = "invoiceNo"
ddl_Invoice.DataBind()

ddl_Invoice.Item.Insert(0,new ListItem("***Select ***","0"))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.