vb.net - Data Access Layer Populate Combobox With Parameters -
i using vb.net (visual studio 2013) , n-tier architecture populate combo box list. code class below
public shared function list() list(of appname.businesslogic.bll_rmcodecomboclass) dim dbo_rmcodelist new list(of appname.businesslogic.bll_rmcodecomboclass) dim conntemp sqlconnection = appclass.getconnection dim strselectsql string = "select [rmcode] [dbo].[rmmaster] [dbo].[rmmaster].[category] = '" & strrmtype & "'" dim strcommandselect new sqlcommand(strselectsql, conntemp) try conntemp.open() dim rdrtemp sqldatareader = strcommandselect.executereader() dim clsdbo_rmcodelist appname.businesslogic.bll_rmcodecomboclass while rdrtemp.read clsdbo_rmcodelist = new businesslogic.bll_rmcodecomboclass clsdbo_rmcodelist.rmcode = system.convert.tostring(rdrtemp("rmcode").tostring) dbo_rmcodelist.add(clsdbo_rmcodelist) loop rdrtemp.close() catch ex sqlexception throw ex conntemp.close() end try return dbo_rmcodelist end function
my objective retrieve or populate combobox rmcodes depending upon type. hence have used strselectsql accordingly. please me pass value of category function becomes dynamic. value of type selected combo box on presentation/ui layer , such code field should populated according category chosen.
thanks in advance cl
e.g.
private function list(type string) list(of thing) '... dim command new sqlcommand("select * mytable @type null or type = @type") command.parameters.add("@type", sqldbtype.nvarchar, 50).value = if(string.isnullorempty(type), cobj(dbnull.value), type) '... end function
that makes filter optional. if pass in nothing
or empty string
sql parameter null
, every record matches, otherwise result set filtered value pass in.
Comments
Post a Comment