2
Im強制使用ODBC,我想將DataSet綁定到FormView。到目前爲止,我有這樣的代碼:將FormView綁定到數據集
Sub lookup(data As String, city As String)
Dim query As String = "SELECT FIND_KORT_VEJ_FUL.STREET_NAME, FIND_KORT_VEJ_FUL.ZIPCODE, UXOR_CITY_DK.NAME AS cityName FROM UXOR_CITY_DK " & _
"Join(FIND_KORT_VEJ_FUL) " & _
"ON UXOR_CITY_DK.KOMMUNE_KODE=FIND_KORT_VEJ_FUL.MUNICIPALITY_CODE WHERE UXOR_CITY_DK.NAME = '" & city & "' " & _
"LIMIT 5"
Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ODBCDataConnectionString").ConnectionString
Dim initialDataSet As New DataSet("initial")
Dim dt As DataSet = GetDataSetFromAdapter(initialDataSet, connectionString, query)
FormView1.DataSource = dt
FormView1.DataBind()
End Sub
Public Function GetDataSetFromAdapter(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New OdbcConnection(connectionString)
Dim adapter As New OdbcDataAdapter(queryString, connection)
' Open the connection and fill the DataSet.
Try
connection.Open()
adapter.Fill(dataSet)
Catch ex As Exception
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
Return dataSet
End Function
FormView控件:
<asp:FormView ID="FormView1" runat="server" EmptyDataText="Ingen data">
<ItemTemplate>
<table>
<tr>
<td>Postnummer: <%#Eval("MUNICIPALITY_CODE") %></td>
</tr>
<tr>
<td>Indbyggere: </td>
</tr>
<tr>
<td>Geografisk lokation: </td>
</tr>
<tr>
<td>Roskilde ligger i <a href="#">Roskilde kommune</a></td>
</tr>
<tr>
<td><br /><h3><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></h3></td>
</tr>
<tr>
<td>Borgmester: </td>
</tr>
<tr>
<td>Antal veje i kommunen: #</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
我已經驗證查詢和查詢字符串,無論是工作。 FormView沒有被填充上面的代碼。是否有可能將FormView綁定到DataSet?還是有更好的方法?
感謝您的快速回答,但它沒有什麼區別,FormView控件仍是空白,當我使用修改過的功能。 – user1359448
@ user1359448你有沒有嘗試在數據綁定上放置一個斷點?如果沒有,那麼確保表格中有行和數據。 – Lopsided
不,我不是在本地開發,代碼託管,並通過FTP工作。如果我直接從管理工作室運行查詢,我會返回數據。 – user1359448