 |
|
ปรึกษาแนวคิดการนำข้อมูลจาก database มาตัดและแสดงใช้วิธีไหนจะได้ผลลัพธ์แบบนี้บ้างคะ |
|
 |
|
|
 |
 |
|
สวัสดีคะพี่ๆ หนูขอคำปรึกษาเรื่องการนำข้อความในดาต้าเบสมาตัด
หนูมีข้อมูลดังนี้

คือว่าหนูต้องการเอาคอลัม coorx กับ coory มาตัดแล้วจับคู่กัน หลักที่ 1 ของ a กับ หลักที่ 1 ของ B
แต่ว่าหนูเขียนออกมาได้แค่ข้อมูลอันเดียว ต้องการทำหลายๆเรคคอด ต้องเขียนโค้ดเพิ่มเติมตรงไหนบ้างไหนคะ
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connect2 As New SqlConnection(sql_db)
Dim cmdsql2 As New SqlCommand
Dim rdr1 As SqlDataReader
cmdsql2.Connection = connect2
cmdsql2.CommandText = "select [ID],[landid],[coorx],[coory],[canetype],[area] from map_plot where landid = '01-251995-03'"
cmdsql2.CommandType = CommandType.Text
' cmdsql2.Parameters.AddWithValue("@supcode", )
Dim str1, str2 As String
Dim strArr(), str2Arr() As String
Try
connect2.Open()
rdr1 = cmdsql2.ExecuteReader()
If rdr1.Read() Then
str1 = rdr1("coorx")
str2 = rdr1("coory")
strArr = str1.Split(",")
str2Arr = str2.Split(",")
'
Dim lst As New List(Of KeyValuePair(Of String, String))
For i As Integer = 0 To strArr.Length - 1
lst.Add(New KeyValuePair(Of String, String)(strArr(i), str2Arr(i)))
Next
Repeater1.DataSource = lst
Repeater1.DataBind()
End If
Catch ex As Exception
' MsgBox(ex.ToString)
connect2.Close()
connect2.Dispose()
End Try
End Sub
asp
Code (ASP)
<table>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container, "DataItem.Key").ToString()%></td>
<td><%# DataBinder.Eval(Container, "DataItem.Value").ToString()%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
ผลลัพ

ต้องการได้ข้อมูลประมาณนี้อ่าคะ แต่ว่าให้มีข้อมูลของแต่ละเเถวออกมาด้วยคะ

ขอคำปรึกษาจากพี่ๆด้วยคะ
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VS 2010 (.NET 4.x), Windows
|
ประวัติการแก้ไข 2015-08-31 10:32:26
|
 |
 |
 |
 |
Date :
2015-08-31 10:31:13 |
By :
mooer |
View :
1025 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ List แบบ Object ครับ
Code (VB.NET)
Public Class ItemClass
Public Property Item1() As String
Get
Return m_Item1
End Get
Set
m_Item1 = Value
End Set
End Property
Private m_Item1 As String
Public Property Item2() As String
Get
Return m_Item2
End Get
Set
m_Item2 = Value
End Set
End Property
Private m_Item2 As String
End Class
Code (VB.NET)
Dim ls As New List(Of ItemClass)()
Code (VB.NET)
For i As Integer = 0 To strArr.Length - 1
ls.Add(New ItemClass() With { _
Key .Item1 = strArr(i), _
Key .Item2 = str2Arr(i) _
})
Next
น่าจะไปต่อได้ครับ
|
 |
 |
 |
 |
Date :
2015-08-31 15:55:01 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connect2 As New SqlConnection(sql_db)
Dim cmdsql2 As New SqlCommand
Dim rdr1 As SqlDataReader
cmdsql2.Connection = connect2
cmdsql2.CommandText = "select [ID],[landid],[coorx],[coory],[canetype],[area] from map_plot where landid like '%251995%' "
cmdsql2.CommandType = CommandType.Text
Try
connect2.Open()
rdr1 = cmdsql2.ExecuteReader()
While rdr1.Read()
lst.Add(New KeyValuePair(Of String, String)(rdr1("landid"), rdr1("canetype")))
add_str_list(rdr1("coorx"), rdr1("coory"))
End While
Repeater1.DataSource = lst
Repeater1.DataBind()
Catch ex As Exception
connect2.Close()
connect2.Dispose()
End Try
End Sub
Function add_str_list(ByVal a As String, ByVal b As String) As String
Dim strArr(), str2Arr() As String
strArr = a.Split(",")
str2Arr = b.Split(",")
For i As Integer = 0 To strArr.Length - 1
lst.Add(New KeyValuePair(Of String, String)(strArr(i), "," & str2Arr(i)))
Next
Return 0
End Function
Code (ASP)
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<%--<td><%# Container.DataItem%></td>--%>
<td><%# DataBinder.Eval(Container, "DataItem.Key").ToString()%><%# DataBinder.Eval(Container, "DataItem.Value").ToString()%></td>
</tr>
<tr></tr>
</ItemTemplate>
</asp:Repeater>
พี่คะ ถ้าเราอยากให้มันแสดงข้อมูลเฉพาะเจาะจง คืออยากให้ ฟิวนี้แสดงตรงนี้อะไรแบบนี้ เราต้องเก็บค่าในอะไรเหรอคะ แล้วตรงที่แสดงใน รีพีตเตอร เราต้องเขียนแบบไหนถึงจะกำหนดตำแหน่งของฟิวที่แสดงได้คะ
|
 |
 |
 |
 |
Date :
2015-09-03 08:39:36 |
By :
mooer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connect2 As New SqlConnection(sql_db)
Dim cmdsql2 As New SqlCommand
Dim rdr1 As SqlDataReader
cmdsql2.Connection = connect2
cmdsql2.CommandText = "select [ID],[landid],[coorx],[coory],[canetype],[area] from map_plot where landid like '%251995%' "
cmdsql2.CommandType = CommandType.Text
Try
connect2.Open()
rdr1 = cmdsql2.ExecuteReader()
While rdr1.Read()
lst.Add(New KeyValuePair(Of String, String)(rdr1("landid"), rdr1("canetype")))
add_str_list(rdr1("coorx"), rdr1("coory"))
End While
Repeater1.DataSource = lst
Repeater1.DataBind()
Catch ex As Exception
connect2.Close()
connect2.Dispose()
End Try
End Sub
Function add_str_list(ByVal a As String, ByVal b As String) As String
Dim strArr(), str2Arr() As String
strArr = a.Split(",")
str2Arr = b.Split(",")
For i As Integer = 0 To strArr.Length - 1
lst.Add(New KeyValuePair(Of String, String)(strArr(i), "," & str2Arr(i)))
Next
Return 0
End Function
Code (ASP)
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container, "DataItem.Key").ToString()%><%# DataBinder.Eval(Container, "DataItem.Value").ToString()%></td>
</tr>
<tr></tr>
</ItemTemplate>
</asp:Repeater>
พี่คะ ถ้าเราอยากให้มันแสดงข้อมูลเฉพาะเจาะจง คืออยากให้ ฟิวนี้แสดงตรงนี้อะไรแบบนี้ เราต้องเก็บค่าในอะไรเหรอคะ แล้วตรงที่แสดงใน รีพีตเตอร เราต้องเขียนแบบไหนถึงจะกำหนดตำแหน่งของฟิวที่แสดงได้คะ
|
ประวัติการแก้ไข 2015-09-03 08:43:28 2015-09-03 08:43:32
 |
 |
 |
 |
Date :
2015-09-03 08:42:35 |
By :
mooer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|