Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.HttpContext
Partial Class how_to_use_CheckBoxList
Inherits System.Web.UI.Page
Dim add As Data.SqlClient.SqlParameter
Dim con As New Data.SqlClient.SqlConnection()
Dim cmd As New Data.SqlClient.SqlCommand()
Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
Label1.Text = "Your speak the following language(s): " & CheckBoxList1.Text
End Sub
Public Sub insert()
con.ConnectionString = "Data Source=YTC-MDN-MONGKOL\APLUS;Initial Catalog=Register;User ID=sa;Password=root"
cmd.CommandText = "INSERT INTO Lanquage(Lanquage,ID)VALUES(@Lan,@ID)"
cmd.Parameters.Add("@Lan", Data.SqlDbType.VarChar).Value = CheckBoxList1.SelectedItem
cmd.Parameters.Add("@ID", Data.SqlDbType.VarChar).Value = Request.Params("ID")
con.Open()
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End Sub
Protected Sub btSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btSubmit.Click
insert()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("<b>Name : " + Request.Params("ID") + "<hr>")
End Sub
End ClassCode (VB.NET)
ตอนนี้เข้าแล้วอ่ะค่ะ แต่เข้าแค่ค่าแรกที่เลือก และในตารางก้แสดงแค่ record เดียวค่ะ ไม่แน่ใจว่าต้องมีการวนลูปรึเปล่าค่ะ ในการที่จะเข้าไปเก็บว่า คนหนึ่งสามารถพูดหลายภาษาได้ โดยแยกเก็บเป็นแต่ละ record รบกวนขอโค้ดให้ด้วยค่ะ
Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.HttpContext
Partial Class how_to_use_CheckBoxList
Inherits System.Web.UI.Page
Dim add As Data.SqlClient.SqlParameter
Dim con As New Data.SqlClient.SqlConnection()
Dim cmd As New Data.SqlClient.SqlCommand()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("<b>Name : " + Request.Params("ID") + "<hr>")
End Sub
Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
Label1.Text = "Your speak the following language(s): " & CheckBoxList1.Text
End Sub
Public Sub insert()
con.ConnectionString = "Data Source=YTC-MDN-MONGKOL\APLUS;Initial Catalog=Register;User ID=sa;Password=root"
cmd.CommandText = "INSERT INTO Lanquage(Lanquage,ID)VALUES(@Lan,@ID)"
cmd.Parameters.Add("@Lan", Data.SqlDbType.VarChar).Value = Label1.Text
cmd.Parameters.Add("@ID", Data.SqlDbType.VarChar).Value = Request.Params("ID")
con.Open()
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End Sub
Protected Sub btSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btSubmit.Click
insert()
End Sub
End ClassCode (VB.NET)