You are getting this error
Arithmetic overflow error converting expression to data type datetime
becouse your date is not in a correct format.
You are are having 10.00 in time. you need to convert the . to :.
HTML
<div>
<asp:DropDownList ID="ddlDurations" runat="server">
<asp:ListItem Text="10.00 - 11.00" Value="10.00 - 11.00" />
<asp:ListItem Text="11.00 - 12.00" Value="11.00 - 12.00" />
<asp:ListItem Text="12.00 - 13.00" Value="12.00 - 13.00" />
</asp:DropDownList>
<asp:Button Text="Save Date" OnClick="SaveDate" runat="server" />
<br />
StartDate
<asp:Label ID="lblStartDate" runat="server" />
End Date
<asp:Label ID="lblEndDate" runat="server" />
<br />
</div>
Namespace
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
C#
protected void SaveDate(object sender, EventArgs e)
{
string endTime = string.Empty;
string startTime = string.Empty;
string dropdownvalue = this.ddlDurations.SelectedItem.Text.ToString();
string et = dropdownvalue.Split('-')[1].ToString();
endTime = "2014-05-15 " + et.Split(' ')[1].ToString();
startTime = "2014-05-15 " + dropdownvalue.Split(' ')[0].ToString();
string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string sqlStatment = "INSERT INTO tblDuration(StartTime,EndTime) VALUES(@StartTime,@EndTime)";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
cmd.Parameters.AddWithValue("@StartTime", Convert.ToDateTime(startTime.Replace('.', ':'), new CultureInfo("en-GB")));
cmd.Parameters.AddWithValue("@EndTime", Convert.ToDateTime(endTime.Replace('.', ':'), new CultureInfo("en-GB")));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
GetDates();
}
private void GetDates()
{
string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string sqlStatment = "SELECT StartTime, EndTime FROM [tblDuration] Where Id = 1 ";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
//where 0 is column index
this.lblStartDate.Text = reader.GetDateTime(0).ToString();
this.lblEndDate.Text = reader.GetDateTime(1).ToString();
}
}
else
{
Response.Write("No rows found.");
}
reader.Close();
}
}
}
SQL
CREATE TABLE [dbo].[tblDuration](
[Id] [int] IDENTITY(1,1) NOT NULL,
[StartTime] [datetime] NOT NULL,
[EndTime] [datetime] NOT NULL
) ON [PRIMARY]
GO