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
2,962 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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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