vb.net - Alternative to the T-SQL AS keyword -
please see code below:
imports system.data.sqlclient imports system.configuration public class form1 private _constring string private sub form1_load(byval sender object, byval e system.eventargs) handles me.load dim objdr sqldatareader dim objcommand sqlcommand dim objcon sqlconnection dim id integer try _constring = configurationmanager.connectionstrings("testconnection").tostring objcon = new sqlconnection(_constring) objcommand = new sqlcommand("select person.urn, car.urn person inner join car on person.urn = car.urn , personid=1") objcommand.connection = objcon objcon.open() objdr = objcommand.executereader(connectionstate.closed) while objdr.read id = objdr("urn") 'line 19 loop objdr.close() catch ex exception throw end try end sub end class
please see line 19. possible similar this:
objdr("person.urn")
when do: objdr("urn") returns carurn , not person urn. realise 1 solution use sql keyword i.e.:
select person.urn personurn, car.urn carurn person inner join car on person.urn = car.urn , personid=1
and then: objdr("personurn")
however, want avoid if possible because of way app designed i.e. involve lot of hard coding.
you can column index, rather name. either of following work:
id = objdr(0) id = objdr.getint32(0)
otherwise, best bet "as" keyword or double-quotes (which ansi standard) create alias.
Comments
Post a Comment