CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Sep 2004
    Posts
    15

    DateTime type in Sql server

    Hi, I have a problem with DateTime type in ADO.NET & Sql Server
    I have the following stored procedure and I executed it successfully in Query Analysis of Sql server. However, if i use it in ADO.NET, it didn't return me any results and it didn't throw any errors.

    This is my stored procedure:
    CREATE PROCEDURE dbo.GetMessages
    (
    @RoomName VARCHAR (100),
    @TimeFrom DATETIME,
    @TimeTo DATETIME
    )
    AS
    SET NOCOUNT ON

    SELECT msg.Content, msg.TimeSent
    FROM Message msg INNER JOIN Room r ON msg.RoomID = r.RoomID
    WHERE r.RoomName = @RoomName
    AND TimeSent >= @TimeFrom AND TimeSent <= @TimeTo


    And this is my method in C#:

    public DataTable GetMessages(string strRoomName, DateTime dtFrom, DateTime dtTo) {
    SqlConnection connection = new SqlConnection(dsn);

    SqlCommand command = new SqlCommand("GetMessages", connection);
    command.CommandType = CommandType.StoredProcedure;

    SqlParameter paramRoomName = new SqlParameter("@RoomName", strRoomName);
    command.Parameters.Add(paramRoomName);

    SqlParameter paramTimeFrom = new SqlParameter("@TimeFrom", SqlDbType.DateTime);
    paramTimeFrom.Value = dtFrom;
    paramTimeFrom.Direction = ParameterDirection.Input;
    command.Parameters.Add(paramTimeFrom);

    SqlParameter paramTimeTo = new SqlParameter("@TimeTo", SqlDbType.DateTime);
    paramTimeTo.Direction = ParameterDirection.Input;
    paramTimeTo.Value = dtTo;
    command.Parameters.Add(paramTimeTo);

    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = command;
    DataTable tblMessages = new DataTable();

    adapter.Fill(tblMessages);
    connection.Close();
    return tblMessages;
    }

    I think there is a difference between DateTime type of C# and Sql Server, but i don't know how to solve it. Please help me!!! Thanks in advance.
    Last edited by bexoan211c; November 18th, 2004 at 11:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured