這種奇怪的行爲今天開始:ASP.NET調用DataAdapter填充創建重複的條目
代碼很簡單:(C#4.5)
布爾connOpened = OpenConnectiontoDB();
SqlCommand cmdCounties = new SqlCommand("spGetCounties", cn);
cmdCounties.CommandType = CommandType.StoredProcedure;
DataSet dsCounties = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmdCounties;
try
{
da.Fill(dsCounties);
}
如果我直接運行存儲過程spGetCounties(單位爲dB),我得到一個值:
ALTER PROCEDURE [dbo].[spGetCounties]
AS
BEGIN
SET NOCOUNT ON;
SELECT c.tblCountyName,c.tblCountyID
FROM
tblCounty c
ORDER BY
c.tblCountyName asc
END
tblCounty不包含任何重複值。
如果我運行的C#代碼,我看dsCounties的價值觀我看到
A
A
B
B
C
C
...
我呼籲在Page_Load事件中的存儲過程。
DataSet dsCounties = new DataSet();
dsCounties = busLayer.GetCounties();
但正如我在看數據庫層代碼這個無所謂,dsCounty的價值是零,並儘快da.Fill(dsCounties)運行我看到dsCounties重複的值。
============================================
更新: 浪費了我2個小時的時間,並試圖削減代碼,並將其與以前的版本進行比較,我意識到這種行爲是由於其他人的簡單但愚蠢的錯誤。
1:新開發人員將Dev端配置文件更改爲指向生產數據庫!
2:我們光榮的DB管理員將每行復制兩次到生產中!我無法想象如何發生這種情況,並忘記把County_ID作爲主鍵。
如果這個問題浪費了你的時間,我很抱歉。
您可以顯示您在代碼中調用過程的位置嗎? –
好的,我更新問題 –
不是浪費時間。經常發生在這裏。我們都在一起(編程的挫敗感):) –