Data Read Using INNER JOIN - Column with same name but different data
Code:
cmd = New SqlCommand("SELECT AlarmDate, OperCode, AcctNum, Name, AlarmZones, Number, ZL.Description, SC.Description FROM " & xDateReport & " as SH " _
& "INNER JOIN Subscriber.dbo.[Subscriber Data] as SD " _
& "ON " _
& "SH.AccountID = SD.AccountID " _
& "INNER JOIN Subscriber.dbo.[Zone Lists] as ZL " _
& "ON " _
& "SH.AccountID = ZL.AccountID " _
& "INNER JOIN MISCELLANEOUS.dbo.[Signal Codes] as SC " _
& "ON " _
& "SH.AlarmCode COLLATE DATABASE_DEFAULT = SC.Code " _
& " where AlarmDate between '" & Fdate1 & "00:00:00' and '" & Fdate2 & "23:59:59' and AlarmZones COLLATE DATABASE_DEFAULT = LTRIM(RTRIM(Number)) order by AlarmDate ASC ", SQLConn)
dr = cmd.ExecuteReader
Do While dr.Read
DataGridView1.Rows.Add(Format(dr("AlarmDate")), dr("OperCode"), dr("AcctNum"), dr("Name"), dr("AlarmZones"), dr(ZL."Description"), dr(SC."Description"))
Loop
dr.Close()
How can I read from selected database.table.column using INNER JOIN with same name but different data.
Thanks
Re: Data Read Using INNER JOIN - Column with same name but different data
By aliasing them...
ZL.Description as ZoneDescription, SC.Description as SignalDescription
-tg
Re: Data Read Using INNER JOIN - Column with same name but different data
Re: Data Read Using INNER JOIN - Column with same name but different data
OT, if you're populating a DataGridView then you shouldn't be loading the data row by row but rather populating a DataTable and binding it. A DataTable has a Load method to which you can pass a data reader.