Go Premium for a chance to win a PS4. Enter to Win

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,393 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

886 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