0
該id將遞增1,如00001.但是無論何時插入新數據,增量都會重新啓動。我希望它從最後一個增量繼續。Id的增量
查詢
string GetMaxIdSql =
@"select isnull(Max(convert(int, ApplicationId)),0) as ApplicationId, isnull(Max(convert(int, Id)),0) as Id from Application where isnumeric(id) = 1 and isnumeric(applicationid) = 1";
命令
resultMaxId.Id = (Convert.ToInt32(resultMaxId.Id) + 1).ToString();
string id = string.Format("{0}", resultMaxId.Id.ToString().PadLeft(6, '0'));
問這可能很愚蠢,但是你確定數據庫表中的'ApplicationId'和'Id'列是'int'類型而不是'varchar',或者它們沒有不可轉換的值不能轉換爲int)。 –
它可能是因爲這些列是字母數字,並試圖將它們轉換爲「int」導致錯誤。 –
如果您的表中存在垃圾數據(其中ID或ApplicationID由於包含字母或其他字符而不是數字)無法轉換,則會發生錯誤。你可以改變查詢來包含'where isnumeric(id)= 1和isnumeric(applicationid)= 1',但實際上你應該修復你的數據。 – ZLK