次のコードは、DataAdapter を生成するようです。
protected void grdMain_Databind()
{
DbProviderFactory dbf = DbProviderFactories.GetFactory();
using (IDbConnection con = dbf.CreateConnection())
{
string sSQL;
sSQL = "select * , " + ControlChars.CrLf
+ " CASE isnull((select TOP 1 EMAIL_ID from EMAILS_ATTACHMENTS WHERE ATTACHMENT_ID=vwFILES_ATTACHMENTS.ATTACHMENT_ID),'00000000-0000-0000-0000-000000000000') " + ControlChars.CrLf
+ " WHEN '00000000-0000-0000-0000-000000000000' THEN '0' ELSE '1' END AS SENT_ATTACHMENT " + ControlChars.CrLf
+ " , case File_ext when '.pdf' then 'true' else 'false' end as 'enablecheck'" + ControlChars.CrLf
+ " , case VISIBLE_TO_CLIENT when '1' then '" + Session["themeURL"].ToString() + "images/check_inline.gif'" + ControlChars.CrLf
+ " else '" + Session["themeURL"].ToString() + "images/close_inline.gif' " + ControlChars.CrLf
+ " end as 'VISIBLE_TO_CLIENT_PATH'" + ControlChars.CrLf
+ " from vwFILES_ATTACHMENTS" + ControlChars.CrLf
+ " where 1 = 1 " + ControlChars.CrLf;
using (IDbCommand cmd = con.CreateCommand())
{
try
{
using (DbDataAdapter da = dbf.CreateDataAdapter())
{
((IDbDataAdapter)da).SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
da.Fill(dt);
vwMain = dt.DefaultView;
grdMain.DataSource = vwMain;
// 09/05/2005 Paul. LinkButton controls will not fire an event unless the the grid is bound.
if (!IsPostBack)
{
//grdMain.SortColumn = "DATE_ENTERED";
//grdMain.SortOrder = "desc";
//grdMain.ApplySort();
}
grdMain.DataBind();
}
}
}
catch (Exception ex)
{
SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
}
}
}
}
そのデータを HTML テーブルに出力するにはどうすればよいですか? 次のことを試しましたが、次のようなエラーが表示されます'dt' does not exist in the current context
。
<% foreach (DataRow row in dt.Rows) { %> <!-- loop through the list -->
<div>
<%= row.ID %> <!-- write out the name of the site -->
</div>
<% } %> <!--End the for loop -->