?
Solved

Urgently?? Cannot use empty object or column names. Use a single space if necessary.

Posted on 2005-03-15
13
Medium Priority
?
1,918 Views
Last Modified: 2008-02-01
What can I do?

Function.

Public Function consultarpor(ByVal strsql As String) As DataSet
        Dim da As New SqlDataAdapter(strsql, dbsiabconn.dbsiabconnection)
        Dim ds As New DataSet
        da.Fill(ds)
        Return ds
    End Function

Caller of the function

   Private Sub btnconsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconsultar.Click
        Dim strsql As String
        If c1.Checked Then
            strsql = "select * from vistacorrespondencia where remitente like '%" & txtremitente.Text & "%'"""
            Dim ds As DataSet
            ds = objconsultas.consultarpor(strsql)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()
        End If
        If c2.Checked Then
            strsql = "select * from vistacorrespondencia where radicara like '%" & txtdestinatario.Text & "%'"""
            Dim ds As DataSet
            ds = objconsultas.consultarpor(strsql)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()
        End If
        If c3.Checked Then
            strsql = "select * from vistacorrespondencia where asunto  like '%" & txtasunto.Text & "%'"""
            Dim ds As DataSet
            ds = objconsultas.consultarpor(strsql)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()
        End If
        If c4.Checked Then
            strsql = "select * from vistacorrespondencia where fecha >=  " & fecha.SelectedDate & " "
            Dim ds As DataSet
            ds = objconsultas.consultarpor(strsql)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()
        End If
   
    End Sub


View.

SELECT     dbo.tblcorrespondencia.num_radi AS Radicado, dbo.tblcorrespondencia.fec_radi AS Fecha, c.remitente, dbo.tblcorrespondencia.Asunto AS Asunto,
                      dbo.tblcorrespondencia.Observacion AS Observacion, dbo.tblFuncionarios.nombre AS Nombre, dbo.tblFuncionarios.radicara AS Radicara,
                      '' AS RecibidoPor, dbo.tblcorrespondencia.nombrearchivo AS Nombrearchivo, dbo.tblcorrespondencia.despachado AS Despachado
FROM         dbo.tblcorrespondencia INNER JOIN
                      dbo.tblremitentesinternos c ON dbo.tblcorrespondencia.Remitente = c.idremitente INNER JOIN
                      dbo.tblFuncionarios ON dbo.tblcorrespondencia.idfuncionario = dbo.tblFuncionarios.idfuncionario
0
Comment
Question by:djhex
[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
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 13544872
Run this query in SQL Query Analyzer and let me know what error it is giving.

Best, Nauman.
0
 
LVL 10

Author Comment

by:djhex
ID: 13544988
No error.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 13545044
Hi djhex,
> strsql = "select * from vistacorrespondencia where fecha >=  " & 
> fecha.SelectedDate & " "

Shouldn't this have ' around it if it is a date field?

strsql = "select * from vistacorrespondencia where fecha >=  '" & fecha.SelectedDate & "' "

Especially if the fecha.SelectedDate value is an empty string.

Tim Cottee
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Author Comment

by:djhex
ID: 13545068
Maybe You are right but I am trying with the first choice. I havent tried the other choices yet.

0
 
LVL 33

Expert Comment

by:raterus
ID: 13545118
I bet it has something to do with the dynamic sql you are using.  Try making a command object in your calling sub, and pass that (use parameters for variables, not dynamic sql -- http://www.knowdotnet.com/articles/dynamisql.html)

            Dim cmd as SqlCommand = new SqlCommand()
            cmd.commandtext = "select * from vistacorrespondencia where fecha >= @fecha"
            cmd.parameters.add(@fecha, fecha.SelectedDate)
            Dim ds As DataSet
            ds = objconsultas.consultarpor(cmd)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()


Public Function consultarpor(ByVal cmd As SqlCommand) As DataSet
        cmd.connection = dbsiabconn.dbsiabconnection
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds)
        Return ds
    End Function
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 13545164
Tim sounds correct :)  There should be single quote in the following SQL query:

strsql = "select * from vistacorrespondencia where fecha >=  '" & fecha.SelectedDate & "' "


HTH, Nauman.
0
 
LVL 10

Author Comment

by:djhex
ID: 13545199
I tried raterus solution but I still get the same error.

Look at my datagrid code maybe it helps.

<asp:DataGrid id="dgconsultas" runat="server" AutoGenerateColumns="False">
                                                <Columns>
                                                      <asp:BoundColumn DataField="Radicado" HeaderText="Radicado"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Fecha" HeaderText="Fecha"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Remitente" HeaderText="Remitente"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Asunto" HeaderText="Asunto"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Observacion" HeaderText="Observacion"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Nombre" HeaderText="Nombre"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="Radicara" HeaderText="Radicara"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="RecibidoPor" HeaderText="Recibido por"></asp:BoundColumn>
                                                      <asp:BoundColumn DataField="nombrearchivo" HeaderText="Nombre Archivo"></asp:BoundColumn>
                                                </Columns>
                                          </asp:DataGrid>
0
 
LVL 10

Author Comment

by:djhex
ID: 13545216
Just trying with the first choice.
If it helps I made an step by step and the error is thrown in  the FILL line of the adapter.

    Public Function consultarpor(ByVal cmd As SqlCommand) As DataSet
        cmd.Connection = New SqlConnection(dbsiabconn.dbsiabconnection)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds)
        Return ds
    End Function


Private Sub btnconsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconsultar.Click
        Dim strsql As String
        If c1.Checked Then
            Dim cmd As SqlCommand = New SqlCommand
            cmd.commandtext = "select * from vistacorrespondencia where remitente like '%" & txtremitente.Text & "%'"""
            Dim ds As DataSet
            ds = objconsultas.consultarpor(cmd)
            dgconsultas.DataSource = ds
            dgconsultas.DataBind()
        End If

0
 
LVL 33

Expert Comment

by:raterus
ID: 13545227
what is the full error, give stack trace...
0
 
LVL 33

Expert Comment

by:raterus
ID: 13545244
stop using dynamic sql (read the link I posted), fix and it you still get error, let me know...
0
 
LVL 10

Author Comment

by:djhex
ID: 13545245
Error de servidor en la aplicación '/dbsiab2'.
--------------------------------------------------------------------------------

Cannot use empty object or column names. Use a single space if necessary.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.

Detalles de la excepción: System.Data.SqlClient.SqlException: Cannot use empty object or column names. Use a single space if necessary.

Error de código fuente:


Línea 50:             cmd.commandtext = "select * from vistacorrespondencia where remitente like '%" & txtremitente.Text & "%'"""
Línea 51:             Dim ds As DataSet
Línea 52:             ds = objconsultas.consultarpor(cmd)
Línea 53:             dgconsultas.DataSource = ds
Línea 54:             dgconsultas.DataBind()
 

Archivo de origen: C:\AplicacionesWeb\DbSiab\consultarcorrespondencia.aspx.vb    Línea: 52

Seguimiento de la pila:


[SqlException: Cannot use empty object or column names. Use a single space if necessary.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
   System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   CsDatos.Consultas.consultarpor(SqlCommand cmd) in C:\Documents and Settings\luisvalen\Mis documentos\Visual Studio Projects\DbSiab\CsDatos\Consultas.vb:322
   DbSiab.consultarcorrespondencia.btnconsultar_Click(Object sender, EventArgs e) in C:\AplicacionesWeb\DbSiab\consultarcorrespondencia.aspx.vb:52
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

 


--------------------------------------------------------------------------------
Información de versión: Versión de Microsoft .NET Framework:1.1.4322.573; Versión de ASP.NET:1.1.4322.573
0
 
LVL 33

Accepted Solution

by:
raterus earned 750 total points
ID: 13545267
txtremitente.Text have a ' in it?  response.write the sql right before it hits sql server and let me know what it looks like.
0
 
LVL 10

Author Comment

by:djhex
ID: 13545311
I found my stupid mistake

'%" & txtremitente.Text & "%'"""

Loot at all those '"" at the end

it should end in  "%' "
and no more.
0

Featured Post

Independent Software Vendors: 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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

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