need help with a really intriguing SqlException RRS feed

  • Question

  • I have extended a table adapter(the one generated with the VS wizard) for one of my tables so i could add an overload to the Fill method to return rows within a certain datetime range from a smalldatetime collumns in the same table

    Code Snippet

            [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill, true)]
            public int Fill(WrkDS.TransferenciasDataTable dataTable, DateTime Data1, DateTime Data2)
                //Instanciar comando com filtro
                string ComandoQuery = "SELECT * FROM Transferencias WHERE Data >= '" + Data1.ToString("yyyyMMdd") + "' and Data <= '" + Data2.ToString("yyyyMMdd") + "'";
                SqlCommand ComandoComFiltro = new SqlCommand(ComandoQuery, this._connection);

                this.Adapter.SelectCommand = ComandoComFiltro;
                if ((this.ClearBeforeFill == true))
                int returnValue = this.Adapter.Fill(dataTable);
                return returnValue;

    as you can see the string "ComandoQuery" is in a valid sql format, in fact I executed the exact same query in SQL server management studio and it returned the rows i wanted but when i try it in my application it trows an SqlException "The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value."

    this is really making my head hurt, i cant seem to figure whats wrong, if someone has any clue please post here.

    Wednesday, June 20, 2007 11:18 PM


All replies

  • Issue resolved.sorry for bothering
    Thursday, June 21, 2007 8:46 AM
  • Hi Thiago,


    I'm glad to hear that it has worked.

    We do appreciate it if you feel free to share the solution so that the answer can be found and used by other community members having similar questions.
      Thank you for your active participation!Smile

    Thursday, June 21, 2007 9:29 AM