Ambiguous column name with my datagrid - confused

I'm confused here.  Its a simple datagrid, with a join.  What am I doing wrong?

\\\\\\\\\\\\\\\\\\\\\ERROR FOLLOWS\\\\\\\\\\\\\\\\\\\\\\\\\

ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Ambiguous column name 'PromotionID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Ambiguous column name 'PromotionID'.

Source Error:


Line 36:         MyCommand = New OdbcDataAdapter("SELECT Promotions_Config.* FROM Promotions INNER JOIN Promotions_Config ON Promotions.PromotionID = Promotions_Config.PromotionID WHERE PromotionID = '" & Request.QueryString("PromotionID") & "'", MyConnection)
Line 37:         DS = New DataSet
Line 38:         MyCommand.Fill(DS, "Promotions")
Line 39:         DataGrid1.DataSource = DS.Tables("Promotions").DefaultView
Line 40:         DataGrid1.DataBind()
 

Dim DS As DataSet
        Dim MyConnection As OdbcConnection
        Dim MyCommand As OdbcDataAdapter
        MyConnection = New OdbcConnection(System.Configuration.ConfigurationSettings.AppSettings("DSNCONNECTION"))
        MyCommand = New OdbcDataAdapter("SELECT Promotions_Config.* FROM Promotions INNER JOIN Promotions_Config ON Promotions.PromotionID = Promotions_Config.PromotionID WHERE PromotionID = '" & Request.QueryString("PromotionID") & "'", MyConnection)
        DS = New DataSet
        MyCommand.Fill(DS, "Promotions")
        DataGrid1.DataSource = DS.Tables("Promotions").DefaultView
        DataGrid1.DataBind()

Open in new window

LVL 2
chrisryhalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sachintana DissanayakeSenior Web DeveloperCommented:
This select statement is using ambiguous naming for the PromotionID column name.
You have to include the table alias near the PromotionID in the where clause like Promotions.PromotionID.
Corrected code is given below...

SELECT Promotions_Config.* FROM Promotions
INNER JOIN Promotions_Config ON Promotions.PromotionID = Promotions_Config.PromotionID
WHERE Promotions.PromotionID = '" & Request.QueryString("PromotionID") & "'", MyConnection)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chrisryhalAuthor Commented:
Thanks for the assistance.  I knew it had to be something simple.  Appreciate it!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.