Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i give the coding in class
VB
Public sub fill_combo(byval ddl as dropdownlist,byval field as string,byval condition s string)
dim dr as sqldatareader
dim a() as string
ddl.items.clear()
dim l as new listitem
l.text="select "
l.value=0
ddl.items.add(l)
dr=viewrecord_dr(field,tbl,condition)
if field.contains(",") then
a=field.split(",")
while dr.read
dim li as new listitem
li.value=dr.item(0)
li.text=dr.item(1)
ddl.items.add(li)
end while
else
while dr.read
ddl.items.add(dr.item(0))
end while
end if
dr.close()
end sub

I give this coding in class
VB
Public function viewrecord_dr(byval field as string,byval condition s string)as sqldatareader
dim query as string 
query="select"
query=query+"from "+tbl
if condition.trim.length>0 
else
query=query
end if
cmd=new sqlcommand (query,con)
dr=cmd.excutereader()
viewrecord_dr=dr
end function

i give this coding in pageload
VB
c.connect()
call c.fill_combo(ddlservicenumber,"servicenumber","tblregistration","")
c.disconnect()

My error is 'invalid column name servicenumberfrom"
please clear this error
Posted
Updated 13-Jul-12 22:13pm
v2
Comments
Kenneth Haugland 14-Jul-12 4:07am    
I dont know exactly but this sounds fishy to me:
dim query as string
query="select"
query=query+"from "+tbl
use & in vb and not +
Sandeep Mewara 14-Jul-12 4:14am    
Did you DEBUG?
Where have you defined: 'servicenumberfrom'?

Spaces my friend, spaces.

As in you don't have any.
You need a space between you need a space between "select" and "servicenumber", you need a space between "servicenumber" and "from".

Add spaces explicitly, and by preference if you are going to assemble strings like that, use a StringBuilder as it is a lot more efficient!
 
Share this answer
 
The last function should look something like this in any case:

VB
Public sub viewrecord_dr(byval field as string,byval condition s string)
dim query as string
query = "select from " & tbl
if tbl = nothing then
exit sub
end if

cmd=new sqlcommand (query,con)
'Where is dr defined?
dr=cmd.excutereader()
'And why not: viewrecord_dr = cmd.excutereader()
viewrecord_dr=dr
end function


Your code looks like it needs a lot of work though....
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900