2017-10-19 4 views
0

私のコードで、次のコードを使用してaspxページにデータを渡します。VB.NETは、For Each Loopを介してWebformsページにDataSetデータを出力します。

Public Function GetFirstElement() As DataSet 
    Dim ds As New DataSet 
    Dim alUtil As New ALUtility 
    Dim connString As String = AppSettings("conSQL") 
    Using cnn As New SqlConnection(connString) 
     cnn.Open() 
     Using dad As New SqlDataAdapter("SELECT TOP 10 * FROM case", cnn) 
      dad.Fill(ds) 
     End Using 
     cnn.Close() 
    End Using 
    Return ds 

End Function 

そして私は、私は次のエラーを取得しています。このループを実行しようとすると、私は次のコード

<% For Each dataRow As Data.DataRow In Me.GetFirstElement().Tables(0).Rows %> 

           <div class="widget-body padset-lg"> 
            <div class="row cancel-paddings"> 
             <div class="col-md-1"> 
             </div> 
             <div class="col-md-11"> 
              <h2 class="darker-text font-size-sm fonts-tight cancel-margin fonts-bold margset-bottom-md"> 
               <%= dataRow["short_description"].ToString() %></h2> 
              <p class="pale-text font-size-sm cancel-margin fonts-bold"> 
               <%= dataRow["case_id"].ToString() %></p> 
              <p class="darker-text font-size-xs fonts-tight fonts-bold cancel-margin"> 
               Medium Priority, New<br /> 
               John Doe ABC Company, 
               <br /> 
               10.23AM, 12/11/2016</p> 
             </div> 
            </div> 
            <div class="card-content height-auto"> 
            </div> 
           </div> 
        </div> 
        <% Next%> 

と内部のaspxページをループしようとしています。

BC30203:識別子が期待されます。

誰かがこの上で私を助けることができます。私はC#プログラマーでVB.NETを初めて使っています。私は正常にC#でループを使用していますが、VBで同じメソッドが動作していません。と私はASPを試した:リピーターも。これで「コンテナが定義されていません」というエラーが表示されます。あなたは括弧を使用する必要があるので、それは、dataRowは、単一の行を表すためにSystem.Data.DataRow配列であることをはっきりと見えるのです

<% For Each dataRow As Data.DataRow In Me.GetFirstElement().Tables(0).Rows %> 

    <%-- omitted --%> 

    <%= dataRow["short_description"].ToString() %> 

    <%-- omitted --%> 

    <%= dataRow["case_id"].ToString() %> 

    <%-- omitted --%> 

<% Next %> 

:我々はASP.NET特殊なものを除くすべてのHTMLマークアップを取り除く場合

答えて

1

は、我々はこのループ構造を取得します

<% For Each dataRow As Data.DataRow In Me.GetFirstElement().Tables(0).Rows %> 

    <%-- omitted --%> 

    <%= dataRow("short_description").ToString() %> 

    <%-- omitted --%> 

    <%= dataRow("case_id").ToString() %> 

    <%-- omitted --%> 

<% Next %> 

参考:

代わりに角括弧 [...]をVB.NETコンテキスト内の列名に言及する

BC30203: Identifier expected

+0

ITSは働いており、あなたの助けをありがとう! – thilanka1989

1

Tyrが、この(あなたのコードの後ろ)場合[DBO]でなければなりません。[ケース]

Public Function GetFirstElement() As DataSet 
    Dim ds As New DataSet 
    Dim alUtil As New ALUtility 
    Dim connString As String = AppSettings("conSQL") 
    Using cnn As New SqlConnection(connString) 
     cnn.Open() 
     Using dad As New SqlDataAdapter("SELECT TOP 10 * FROM [dbo].[case]", cnn) 
      dad.Fill(ds) 
     End Using 
     cnn.Close() 
    End Using 
    Return ds 

End Function 

あなたのASPXコード<% =のDataRow [ "SHORT_DESCRIPTION"]。ToStringメソッド()%><% =のDataRowでなければならない( "SHORT_DESCRIPTION")。ToStringメソッド()%>

<div class="widget-body padset-lg"> 
     <div class="row cancel-paddings"> 
      <div class="col-md-1"> 
      </div> 
       <div class="col-md-11"> 
       <h2 class="darker-text font-size-sm fonts-tight cancel-margin fonts-bold margset-bottom-md"> 
       <%= dataRow("short_description").ToString() %></h2> 
       <p class="pale-text font-size-sm cancel-margin fonts-bold"> 
       <%= dataRow("case_id").ToString() %></p> 
       <p class="darker-text font-size-xs fonts-tight fonts-bold cancel-margin"> 
       Medium Priority, New<br /> 
       John Doe ABC Company, 
       <br /> 
       10.23AM, 12/11/2016</p> 
       </div> 
      </div> 
     <div class="card-content height-auto"> 
     </div> 
    </div> 
関連する問題