1
我有一箇中繼器,我試圖顯示基於sql語句的數據。但是,由於某種原因,如果我在轉發器中有多個相同條目的行,它只會顯示一個。例如:.net中繼器刪除重複數據
在數據庫(informix的):
- 扣減工資250.00
- 扣減工資250.00
- 扣減工資250.00
- 扣減工資250.00
- 學生健康保險1100.00
顯示在轉發:
- 扣減工資250.00
- 學生健康保險1100.00
任何想法,這可能是爲什麼?我在代碼中使用的SQL(下面)在我在數據庫中運行時工作正常。
private DataTable GetCreditData (string id, string sessyr)
{
OdbcConnection conn = new OdbcConnection ();
conn.ConnectionString = cxConnStr;
// Define our SQL
String sql = "select ABS(t1.amt) as amt , t2.txt from subtr_rec t1, subt_table t2 where t1.subs = 'S/A' and t1.tot_prd = ? and t1.subs_no=? and t1.amt < 0 and t1.tot_code = t2.tot_code and t1.subs = t2.subs UNION select t1.amt, t2.txt from aid_rec t1 join aid_table t2 on t1.aid=t2.aid where t1.sess =? and t1.yr = ? and t1.id = ? and ((stat='A' and amt_stat='AA') or (stat='I' or amt_stat='AA'))";
// Command
OdbcCommand command = new OdbcCommand ();
command.Connection = conn;
command.CommandText = sql;
command.Parameters.Add (new OdbcParameter ("sess", sessyr));
command.Parameters.Add (new OdbcParameter ("id", id));
command.Parameters.Add (new OdbcParameter ("sess2", CurrSess));
command.Parameters.Add (new OdbcParameter ("yr", CurrentYr));
command.Parameters.Add (new OdbcParameter ("id2", id));
// Create a DataTable to store our Cached results.
DataTable dt = new DataTable ();
// Create a DataAdapter used to fill the DataTable
OdbcDataAdapter dataAdapter = new OdbcDataAdapter ();
// Associate the DataAdapter and select command created above
dataAdapter.SelectCommand = command;
try
{
// Open Database.
conn.Open ();
// Fill DataTable.
dataAdapter.Fill (dt);
}
catch (Exception ex)
{
edException.Error = ex;
this.ParentPortlet.ShowFeedback (FeedbackType.Message, "There was an error looking up term credits.");
}
finally
{
if (conn != null && conn.State == ConnectionState.Open)
{
// Release our resources (close db connection)
conn.Close ();
}
}
return dt;
}
這裏就是數據表綁定到一箇中繼器(的Page_Load):
DataTable creditdata = GetCreditData (Host, CurrSess + CurrentYr.Remove (0, 2));
TermCredits.DataSource = creditdata;
TermCredits.DataBind ();
您是否能夠針對數據庫運行SQL以查看它返回的內容 - 通過這種方式我們可以確定它是SQL命令問題還是中繼器本身! – Bertie 2012-01-31 15:55:42
這個問題是在與SQL語句中的聯盟。該聯盟應該是「Union All」,以防止刪除重複項。 – MogulBomb 2012-01-31 16:40:58
@NLarkin你應該刪掉這個問題 – Magnus 2012-01-31 16:54:40