พี่ช่วยดู code ให้หน่อยไม่รู้ว่าทามไม insert ลง DB ไม่ได้อ่า
Code (ASP)
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Security.Cryptography
Imports System.Text
Partial Class register_school_result
Inherits System.Web.UI.Page
Public Function MD5(ByVal strString As String) As String
Dim ASCIIenc As New ASCIIEncoding
Dim strReturn As String
Dim ByteSourceText() As Byte = ASCIIenc.GetBytes(strString)
Dim Md5Hash As New MD5CryptoServiceProvider
Dim ByteHash() As Byte = Md5Hash.ComputeHash(ByteSourceText)
For Each b As Byte In ByteHash
strReturn = strReturn & b.ToString("x2")
Next
Return strReturn
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String = WebConfigurationManager.ConnectionStrings("Genius").ConnectionString
Dim Conn As New SqlConnection(strConn)
Conn.Open()
Dim ID As String
ID = "Sc_" + date("U")
Dim Username = Session("Username")
Dim email = Session("Email")
Dim Name_Sc = Session("Name_Sc")
Dim Type_Sc = Session("Type_Sc")
Dim headmaster = Session("headmaster")
Dim headgroup = Session("headgroup")
Dim headsection = Session("headsection")
Dim connector = Session("connector")
Dim street = Session("street")
Dim Alley = Session("Alley")
Dim district = Session("district")
Dim boundary = Session("boundary")
Dim province = Session("province")
Dim tel_Sc = Session("tel_Sc")
Dim tel_connect = Session("tel_connect")
Dim fax = Session("fax")
Dim encode As String = MD5(Session("Pass").ToString)
Dim sqlAdd As String
Dim comAdd As New SqlCommand
Try
sqlAdd = "INSERT INTO school(ID_Sc,Username,Password,Name_Sc,ID_Type_Sc,headmaster,headgroup,headsection,connect,Street_Sc,Alley_Sc,District_Sc,Boundary_Sc,Province_Sc,Tel_Sc,Tel_connect,Fax_Sc,Email_Sc)"
sqlAdd &= "VALUES('" & ID.ToString & "',"
sqlAdd &= "'" & Username.ToString & "',"
sqlAdd &= "'" & encode.ToString & "',"
sqlAdd &= "'" & Name_Sc.ToString & "',"
sqlAdd &= "'" & Type_Sc.ToString & "',"
sqlAdd &= "'" & headmaster.ToString & "',"
sqlAdd &= "'" & headgroup.ToString & "',"
sqlAdd &= "'" & headsection.ToString & "',"
sqlAdd &= "'" & connector.ToString & "',"
sqlAdd &= "'" & street.ToString & "',"
sqlAdd &= "'" & Alley.ToString & "',"
sqlAdd &= "'" & district.ToString & "',"
sqlAdd &= "'" & boundary.ToString & "',"
sqlAdd &= "'" & province.ToString & "',"
sqlAdd &= "'" & tel_Sc.ToString & "',"
sqlAdd &= "'" & tel_connect.ToString & "',"
sqlAdd &= "'" & fax.ToString & "',"
sqlAdd &= "'" & email.ToString & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
.ExecuteNonQuery()
End With
Catch ex As Exception
MsgBox("ไม่สามารถเพิ่มข้อมูลได้", MsgBoxStyle.OkOnly) '
Finally
Conn.Close()
End Try
MsgBox("เพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.OkOnly)
result.Text = "ระบบบันทึกข้อมูลของท่านเรียบร้อย เราจะติดต่อกลับไปที่ท่านภายหลัง"
End Sub
End Class