0

The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value code is as follows:

Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim adap As SqlDataAdapter Dim cn As SqlConnection Dim cmd As SqlCommand Dim ds As DataSet Dim dt As DataTable Dim str, constr As String Dim rdr As SqlDataReader Dim errmsg As String Dim erflag As Boolean Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick If (dsr_no1.Visible = True) Then cn = New SqlConnection() cn = New System.Data.SqlClient.SqlConnection() cn.ConnectionString = "Data Source=PANKAJ\PANKAJSQL;Initial Catalog=Database;Integrated Security=True" cn = New SqlConnection(Application("constr")) cn = New SqlConnection() cn = New System.Data.SqlClient.SqlConnection() cn.ConnectionString = "Data Source=PANKAJ\PANKAJSQL;Initial Catalog=Database;Integrated Security=True" Dim i As Integer i = dsr_no.Text While (i < Val(dsr_no.Text) + Val(Quantity.Text)) cn = New SqlConnection() cn = New System.Data.SqlClient.SqlConnection() cn.ConnectionString = "Data Source=PANKAJ\PANKAJSQL;Initial Catalog=Database;Integrated Security=True" cn = New SqlConnection(Application("constr")) cn = New SqlConnection() cn = New System.Data.SqlClient.SqlConnection() cn.ConnectionString = "Data Source=PANKAJ\PANKAJSQL;Initial Catalog=Database;Integrated Security=True" str = "insert into dsr_main values (" + i.ToString + "," str = str + "'" + Location.Text + "'," str = str + "'" + Remarks.Text + "'," str = str + "'" + Date.Today.ToShortDateString + "'," str = str + "'" + Application("username") + "'," str = str + Val(ds

28th Mar 2017, 1:19 PM
pankaj
pankaj - avatar
1 Respuesta
0
I think it's different culture settings that are breaking your code. DD/MM vs MM/DD Try replacing this: Date.Today.ToShortDateString with: String.Format("{0:YYYYMMDD}", Date.Today) SQL Server always understands dates written in YYYYMMDD, regardless of culture settings of the database.
7th Apr 2017, 2:11 PM
Gijs van Dam
Gijs van Dam - avatar