Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed.

Posted on 2013-01-04
4
Medium Priority
?
3,272 Views
Last Modified: 2013-01-04
I am getting the error An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
Unclosed quotation mark after the character string ''.

the below code gives me the error

   cmd.CommandText = "select * from Holidays where Username =@amorpm and Date < '" & enddate.AddDays(1).ToShortDateString & "' and Date > '" & startdate.AddDays(-1).ToShortDateString & "' "

Open in new window


i have tried   cmd.CommandText = "select * from Holidays where Username =@amorpm
and this works fine so the error seems to lie within the date.

The dates are stored as dd/mm/yyyy 00:00:00 and are all filled
0
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 2000 total points
ID: 38743434
There might be an issue with "Date" column name, try the following:
cmd.CommandText = "select * from Holidays where Username = @amorpm and [Date] < '" & enddate.AddDays(1).ToShortDateString & "' and [Date] > '" & startdate.AddDays(-1).ToShortDateString & "' "
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38743488
try with the harcoded values in SQL staement for date option
if that works fins

debig and check the SQL statement created , will it be same as harcoded
0
 

Author Comment

by:runnerjp2005
ID: 38743499
with i get The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

whole code is here
 
If DateTime.Now.Month = "1" Or DateTime.Now.Month = "2" Or DateTime.Now.Month = "3" Then
            whatyear = DateTime.Now.Year - 1
            whatyear2 = DateTime.Now.Year
        Else
            whatyear = DateTime.Now.Year
            whatyear2 = DateTime.Now.Year + 1
        End If
 Dim startdate As Date = CDate("01/04/" & whatyear)
        Dim enddate As Date = CDate("31/03/" & whatyear2)
       
        Try
            cmd.Parameters.AddWithValue("@amorpm", myname)
            cmd.CommandText = "select * from Holidays where Username =@amorpm and [Date] < '" & enddate.AddDays(1).ToShortDateString & "' and [Date] > '" & startdate.AddDays(-1).ToShortDateString & "' "

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38743514
have you cheked what values are you getting for
enddate.AddDays(1).ToShortDateString  and  startdate.AddDays(-1).ToShortDateString

will that be valid ?
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question