• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

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

0
chrisryhal
Asked:
chrisryhal
1 Solution
 
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
 
chrisryhalAuthor Commented:
Thanks for the assistance.  I knew it had to be something simple.  Appreciate it!!!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now