Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlStr = "select ROW_NUMBER() OVER (ORDER BY id) AS [Sno],Employees.EmpID,Employees.contactno,Empname as [Employee Name],WorkType,ClientName,SiteName,Siteschedule.TotalHours AS [Total Working Hours] from Siteschedule inner join clients on clients.clientid=Siteschedule.clientid inner join sites on sites.SiteID=Siteschedule.SiteID inner join Employees on Employees.EmpID=Siteschedule.empid where (StartDateValue between " & TxtStartDate.Value.Date.ToOADate & " and " & TxtEndDate.Value.Date.ToOADate & ") " & substring

when innerjoining error is ambigous columnname id

What I have tried:

i have tried one solution but not change same error
Posted
Updated 12-Jul-18 9:12am

Based on what posted here. This query is referencing the id column
SQL
select ROW_NUMBER() OVER (ORDER BY id)


The id column could exists in more than one tables

Siteschedule
clients
sites
Employees

To solve this error, you can update the code to use table alias and then update this piece "ORDER BY id" to something like ORDER BY [Table Alias].id

SQL Aliases[^]

By the way, I would also suggest to use Parameterized query
https://www.aspsnippets.com/Articles/Using-Parameterized-queries-to-prevent-SQL-Injection-Attacks-in-SQL-Server.aspx
 
Share this answer
 
That error means there is a column ID in multiple tables; and the query does not know which one you want. To fix it, qualify it with the table name.
That said, fix your WHERE clause as it is ripe for SQL Injection; NEVER EVER build an Sql Command using string methods, what you should use are Parameters

C#
// just the WHERE condition of the statement for brevity
SqlStr ="WHERE (StartDateValue BETWEEN @StartDate AND @EndDate)" 
cmd.Parameters.AddWithValue("@StartDate", TxtStartDate.Value.Date.ToOADate);
cmd.Parameters.AddWithValue("@EndDate", TxtEndDate.Value.Date.ToOADate);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900