Saving data into SqlServer

Posted on 2011-05-05
Last Modified: 2012-05-11
Hello experts,

Will you please help me find why I can't save the date and Time in SqlServer database.

I am attaching a snap shot of the table design where the data should be saved. I am also attaching the code in which saves the data into the table.

The problem is simple, the record is saved except for the dData and tTime columns. I get 00:00:00 in the dDate column and 1900-01-01 in the tTime column

The date and time are initially entered into two separate text Boxes  "txtDate" and "txtTime":
The code for entering the date is :

dim currentDate as date = Now
txtDate.Text = currentDate.ToShortDateString

as for entering time the code is:

dim currentTime as date =Now
txtTime.text = currentTime.ToShortTimeString

Below is the code for inserting the data into the table


 table design
Dim con As SqlConnection
        Dim comm As SqlCommand

        con = New SqlConnection("Server=Adam\; Database=HelpDesk;Integrated Security=True")
        ' create the INSERT query 
        Dim strQuery As String = "INSERT INTO Main (dDate,tTime,nName,sSubject,mMonth,tType,Remarks) VALUES (@dDate,@tTime,@nName,@sSubject,@mMonth,@tType,@remarks);"
        comm = New SqlCommand(strQuery, con)
        comm.Parameters.AddWithValue("@dDate", System.Data.SqlDbType.Date)
        comm.Parameters("@dDate").Value = Me.txtDate.Text
        comm.Parameters.AddWithValue("@tTime", System.Data.SqlDbType.Time)
        comm.Parameters("@tTime").Value = Me.txtTime.Text
        comm.Parameters.AddWithValue("@nName", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@nName").Value = txtName.Text
        comm.Parameters.AddWithValue("@sSubject", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@sSubject").Value = txtSubject.Text
        comm.Parameters.AddWithValue("@mMonth", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@mMonth").Value = txtMonth.Text
        comm.Parameters.AddWithValue("@tType", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@tType").Value = txtType.Text
        comm.Parameters.AddWithValue("@Remarks", System.Data.SqlDbType.NVarChar)
        comm.Parameters("@Remarks").Value = txtRemarks.Text
            ' Execute the command
        End Try

Open in new window

Question by:adamtrask
    LVL 1

    Accepted Solution

    please Check in the data type
    If I am not wrong
    in the date Field you have taken Time as Datatype
    and in the time Field you have Taken date as Datatype

    are you using SQl ,which version
    check it and then reply

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my 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…
    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now