2017-12-08 16 views
0

私のデータベースからテーブルの数を表示しようとしています。私は行のカウントを返す関数を持っています。私はC#を初めて使っていて、HTMLの関数をどのように呼び出すかわからないので、返された値が表示されます。C#関数からの戻り値を取得し、htmlで表示

は、ここで私はHow to count the number of rows from sql table in c#?からもらった私のC#の機能です:

public int Get_Count(object sender, EventArgs e) 
{ 
    { 
     string stmt = "SELECT COUNT(*) FROM dbo.listing"; 
     int count = 0; 

     using (SqlConnection thisConnection = new SqlConnection("Data Source=DATASOURCE")) 
     { 
      using (SqlCommand cmdCount = new SqlCommand(stmt, thisConnection)) 
      { 
       thisConnection.Open(); 
       count = (int)cmdCount.ExecuteScalar(); 
      } 
     } 
     return count; 
    } 
} 

そして、ここで私が返されるカウントを表示したいHTMLの行です:ページロードイベントで

<p class="lead text-muted block text-center"><strong>Get_Count()</strong> results found</p> 
+1

このMVCまたはWebFormsですか? – itsme86

+0

私はWebFormsを使用しています – dginos3

+0

WebFormsアプリケーションが呼び出しているWeb API/WCFサービスはありますか、これはDALインターフェイス(アプリケーションが使用しているアセンブリ)を経由しています。 – rlcrews

答えて

1

<p class="lead text-muted block text-center"><strong><%# Get_Count() %></strong> results found</p> 
関連する問題