Sub ShowName()
Dim objconn As SqlConnection
Dim objcmd As SqlCommand
Dim strconn As String
Dim strcmd As String
strconn = ConfigurationManager.AppSettings("ConnectionString")
objconn = New SqlConnection(strconn)
objconn.Open()
strcmd = "select ID,NAME,LASTNAME from USERS"
objcmd = New SqlCommand(strcmd, objconn)
ddlcostcen.DataSource = objcmd.ExecuteReader()
ddlcostcen.DataTextField = ("NAME") 'บรรทัดนี้อ่ะครับ ที่ไม่รู้จะใส่ค่ายังไงให้ มัน Show ค่าออกมาแบบนั้น
ddlcostcen.DataValueField = ("ID")
ddlcostcen.DataBind()
ddlcostcen.DataSource.close()
objconn.Close()
End Sub
Sub ShowName()
Dim objconn As SqlConnection
Dim objcmd As SqlCommand
Dim objReader As SqlDataReader
Dim strconn As String
Dim strcmd As String
strconn = ConfigurationManager.AppSettings("ConnectionString")
objconn = New SqlConnection(strconn)
objconn.Open()
strcmd = "select ID,NAME,LASTNAME from USERS"
objcmd = New SqlCommand(strcmd, objconn)
objReader = objcmd.ExecuteReader()
While objReader.Read()
ddlcostcen.Items.Add(New ListItem(String.Format("{0} {1} {2}", objReader("ID").ToString(), objReader("NAME").ToString(), objReader("LASTNAME").ToString()), objReader("ID").ToString()))
End While
objconn.Close()
End Sub