sql - Connect a web service to a database and display information -
i beginner vb.net developer , wanted know how create web service , connect sql 2012 database , display item in table. database table has several fields including stock item, manufacturer, free stock quantity, price, etc..
if add breakpoint , step through code, can see value passed string in recordset , returned, however, isn't display properly. i've changed server, username , password thats code shown below.
public class service1 inherits system.web.services.webservice private sqlconnection adodb.connection <webmethod()> _ public function showstockitems() string dim command new sqlcommand sqlconnection = new adodb.connection sqlconnection.connectionstring = "driver={sql server};server=server;uid=id;pwd=password;database=able_instruments" try sqlconnection.open() dim strreturn string = "" dim rststockitem new adodb.recordset dim strstockitem string = "select * stockitem" rststockitem.open(strstockitem, sqlconnection) rststockitem if not .bof .movefirst() strreturn = .fields.item("taxcodeid").value end if![enter image description here][1] end rststockitem.close() sqlconnection.close() 'return strreturn catch ex exception end try end function end class
i'm not sure if problem obvious i'd able display id of stock item , name of stock item. example used taxcodeid make sure code working correctly. using visual studio 2010 , have access 2013 if need be.
http://i.stack.imgur.com/kwj14.png
thanks help!
when not using entity framework build classes complexed data retrieval.
public class stockitem public property name string public property id integer 'others needed end class
usage:
<webmethod()> _ public function showstockitems() stockitem dim _stockitem new stockitem dim command new sqlcommand sqlconnection = new adodb.connection sqlconnection.connectionstring = "driver={sql server};server=server;uid=id;pwd=password;database=able_instruments" try sqlconnection.open() dim strreturn string = "" dim rststockitem new adodb.recordset dim strstockitem string = "select * stockitem" rststockitem.open(strstockitem, sqlconnection) rststockitem if not .bof .movefirst() _stockitem.id = convert.toint32(.fields.item("taxcodeid").value) _stockitem.name = .fields.item("what field need).value end if end catch rststockitem.close() sqlconnection.close() end try return _stockitem end function
Comments
Post a Comment