มัน error แบบนี้ค่ะ
Record can not insert Error (The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated.)
มันไม่ขึ้น อันนี้แล้วค่ะ
Record can not insert Error (The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated.)
แต่มันไปขึ้นอันนี้แทน
Record can not insert Error (Incorrect syntax near '20'.)
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.IO" %>
<script runat="server">
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim intNumRows As Integer
Dim strConnString, strSQL As String
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub btnsubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
strConnString = "Server=localhost;UID=sa;PASSWORD=12345678;database=blooddb;Max Pool Size=400;Connect Timeout=600;"
objConn.ConnectionString = strConnString
objConn.Open()
Dim dtNow As DateTime = DateTime.Now
Dim year1 As String = DropDownList5.Text
Dim Month1 As String = DropDownList4.Text
Dim days As String = DropDownList3.Text
If DropDownList4.Text = "January" Then
Month1 = "01"
ElseIf DropDownList4.Text = "Febuary" Then
Month1 = "02"
ElseIf DropDownList4.Text = "March" Then
Month1 = "03"
ElseIf DropDownList4.Text = "April" Then
Month1 = "04"
ElseIf DropDownList4.Text = "May" Then
Month1 = "05"
ElseIf DropDownList4.Text = "June" Then
Month1 = "06"
ElseIf DropDownList4.Text = "July" Then
Month1 = "07"
ElseIf DropDownList4.Text = "August" Then
Month1 = "08"
ElseIf DropDownList4.Text = "September" Then
Month1 = "09"
ElseIf DropDownList4.Text = "October" Then
Month1 = "10"
ElseIf DropDownList4.Text = "November" Then
Month1 = "11"
ElseIf DropDownList4.Text = "December" Then
Month1 = "12"
End If
Dim y As Integer = Convert.ToInt32(year1) - 543
Dim tranDate As String = y.ToString() + "-" + Month1 + "-" + days
Dim myDate As DateTime
myDate = Format(DateTime.Now, tranDate)
'*** DataTable ***'
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
strSQL = "SELECT Max(LastModify) FROM CallEmerge WHERE BloodGroup = '" & Me.DropDownList1.Text & "' And Username ='" & Session("User_session1") & "' "
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM callemerge WHERE BloodGroup = '" & Me.DropDownList1.Text & "' And Username='" & Session("User_session1") & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
If IsNumeric(TextBox2.Text) = True Then
If TextBox2.Text <> "" Then
strSQL = " UPDATE CallEmerge SET Username ='" & Session("User_session1") & "',BloodGroup = '" & Me.DropDownList1.Text & "',Quantity = '" & Me.TextBox2.Text & "',Urgency = " & myDate & ",Lastmodify = " & dtNow & ""
ElseIf TextBox2.Text = "" Then
Label14.Text = "please insert data"
End If
Else
Label14.Text = "Invalid data.This must be number."
End If
Else
If IsNumeric(TextBox2.Text) = True Then
If TextBox2.Text <> "" Then
strSQL = "INSERT INTO CallEmerge (Username,BloodGroup,Quantity,Urgency,LastModify) " & " VALUES " & " ('" & Session("User_session1") & "','" & Me.DropDownList1.Text & "','" & Me.TextBox2.Text & "'," & myDate & "," & dtNow & ")"
ElseIf TextBox2.Text = "" Then
Label14.Text = "please insert data"
End If
Else
Label14.Text = "Invalid data.This must be number."
End If
End If
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Label9.Text = ""
Label9.Text = "Record Insert"
Label9.Visible = True
Catch ex As Exception
Label9.Visible = True
Label9.Text = "Record can not insert Error (" & ex.Message & ")"
End Try
objConn.Close()
objConn = Nothing
End Sub
Sub btnLogOut_Click(ByVal sender As Object, ByVal e As EventArgs)
Session.Clear()
Session("Login") = "Off"
Response.Redirect("http://localhost/home/home.aspx")
End Sub
Sub btnback_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("http://localhost/home/menu.aspx")
End Sub
</script>