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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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