Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:41:26+00:00 2026-06-04T10:41:26+00:00

I have 2 textboxes, txtStartDate.Text and txtEndDate.Text, user choose date through calendar date picker.

  • 0

I have 2 textboxes, txtStartDate.Text and txtEndDate.Text, user choose date through calendar date picker.
Now I want to count the days between the two selected date and save the result in the database field totalDay(type integer), the following is my code:

But when I click button and try to save it into database, i receive this error:

The version of SQL Server in use does not support datatype ‘time’.

What should I do to overcome this problem?

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Globalization

Partial Class addevent
Inherits System.Web.UI.Page

Protected Sub ButtonAddEvent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddEvent.Click

    Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
    '"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\eventdb.mdf;Integrated Security=True;User Instance=True"
    Dim con As SqlConnection = New SqlConnection(connString)

    Dim cmdQuery As String = "INSERT INTO eventinfo(venue,totalDay,eventTitle,startDate,endDate,description) VALUES (@venue,@totalDay,@eventTitle,@startDate,@endDate,@description)"
    Dim cmd = New SqlCommand(cmdQuery)
    cmd.Connection = con
    cmd.CommandType = CommandType.Text
    con.Open()
    cmd.Parameters.AddWithValue("@eventTitle", txtEventTitle.Text)
    cmd.Parameters.AddWithValue("@venue", txtEventLocation.Text)
    cmd.Parameters.AddWithValue("@startDate", txtStartDate.Text)
    cmd.Parameters.AddWithValue("@endDate", txtEndDate.Text)
    cmd.Parameters.AddWithValue("@description", txtEventDescription.Text)

    Dim fmt As String = "dd/MM/yyyy"
    Dim dtStart As DateTime = DateTime.ParseExact(txtStartDate.Text, fmt, Nothing)
    Dim dtEnd As DateTime = DateTime.ParseExact(txtEndDate.Text, fmt, Nothing)

    Dim ts As TimeSpan = dtEnd - dtStart

    cmd.Parameters.AddWithValue("@totalDay", ts.TotalDays)


    cmd.ExecuteNonQuery()
    cmd.Parameters.Clear()
    con.Close()

    Response.Redirect("~/addbooth.aspx")

End Sub
End Class

My table structure:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:41:27+00:00Added an answer on June 4, 2026 at 10:41 am

    As your field is of type integer, and you only let users input days without a time component, the following could work:

    cmd.Parameters.AddWithValue("@totalDay", ts.Days)
    

    TimeSpan.TotalDays gives you days and fractions of days as a double, TimeSpan.Days only the whole days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some textboxes on a page and I want to click a link
i have 2 textboxes that i am filling with StartDate, and Endate. i want
I'm using the jQuery datepicker where I have two textboxes (start date / end
I have textboxes where i only want signed a max number of characters in.
I have multiple textboxes in my form like txtTask0, txtTask1... txtTask12. so I want
I have 7 textboxes. If Top 1 textbox( Volume All Years ) text changed,
I have two textboxes, and a button. When I press the button, I want
Possible Duplicate: Text box validation not working Right now I have 5 text boxes
I have textboxes loaded with data on my ASP.NET MVC page. If the user
I have multiple textboxes on my page, their ID starts with 'Text' and followed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.