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,739 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now