Wednesday, January 10, 2007

my own GetData function for Datasource

this is the function i wrote for datasource for databound control like
..bullettedlist ,datagrid.. etc...

Fuction Definition

Function getdata(ByVal qry As String, ByVal tablename As String) As DataSet
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(qry, obj.dbcon)
da.Fill(ds, "tablename")
Return ds
End Function


Fuction Calling

bllTest.DataSource = getdata("SELECT Name, AVG(Salary) AS avg_salar FROM tblTest GROUP BY Name", "tblTest")

" bllTest " is the sample bulletted list control ID .... then u can add this 2 lines

bllTest.DataTextField = "Name" ( Only for List Databound control --" only one column" )
bllTest.DataBind() ( For all Databound control )

note :
If u write this Function in public class u can access the function in any where ur application ...

No comments: