vb.net - Microsoft SQL Server SELECT statement -


i need retrieving receiptno column database table , saving textbox or label referencing.

code:

dim da2 new sqldataadapter da2.selectcommand = new sqlcommand("select recepitno receipt (paidfor=@paidfor , regno=@regno)") da2.selectcommand.parameters.add("@paidfor", sqldbtype.varchar).value = cbmonth.text da2.selectcommand.parameters.add("@regno", sqldbtype.int).value = lblregno.text  cn.open() da2.update(ds.tables("receipt")) 'da2.selectcommand.executenonquery() da2.selectcommand.executereader() cn.close() 

you need use sqldatareader, , start loop read values returned
example work assuming receiptno text field

cn.open() dim reader = da2.selectcommand.executereader() while reader.read()     textbox1.text = reader("receiptno").tostring() end while 

in alternative, if sure query returns 0 or 1 record , interested in receiptno field, can use executescalar

dim cmd = new sqlcommand("select recepitno receipt (paidfor=@paidfor , regno=@regno)") cmd.connection = cn cmd.parameters.add("@paidfor", sqldbtype.varchar).value = cbmonth.text cmd.parameters.add("@regno", sqldbtype.int).value = lblregno.text cn.open() dim result = cmd.executescalar() if result isnot nothing     textbox1.text = result.tostring() end if 

here msdn docs on executescalar


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -