我在一个ASP.Net页面中使用了一些存储过程。我经常在引号之间使用行号或行名,但我找不到按名称访问内连接表的方法:
Dim conn As New SqlConnection("my_connection_string")
Dim mycommand As New SqlCommand("last_played_songs", conn)
mycommand.CommandType = CommandType.StoredProcedure
mycommand.Parameters.AddWithValue("@userid", userid)
conn.Open()
Dim dr As SqlDataReader = mycommand.ExecuteReader()
While dr.Read()
/* What I have: */
Dim artist_image As String = dr(39) & "" & "/cover.jpg"
/* What I want. Let's say I called my table ArtistProfile under inner join: */
Dim artist_image As String = dr("ArtistProfile.uniqueID") & "/cover.jpg"
End While看起来使用用于inner join的名称并不是一个好的语法,但是我不知道如何命名它才能访问“inner-join”表。数字索引的问题是,如果4-5个连接表中的一个结构改变,所有索引都会改变。
发布于 2012-11-27 11:04:21
为存储过程中的字段名添加别名,以获得所需的输出
select
TableA.Name as 'TableA.Name',
TableA.Age as 'TableA.Age',
TableB.Address as 'TableB.Address'
from
TableA INNER JOIN TableB ON TableA.ID = TableB.ID
-- Example using table alias in SQL
select
a.Name as 'TableA.Name',
a.Age as 'TableA.Age',
b.Address as 'TableB.Address'
from
TableA a INNER JOIN TableB b ON a.ID = b.IDhttps://stackoverflow.com/questions/13576533
复制相似问题