試圖更改我的SQL語句以更改創建用戶名的格式。我正在創建虛擬數據以便在網頁上進行測試,所以我只需要多個用戶。我想爲用戶更改名稱目前是student{integer}@email.com
,我想改名字student{integer}
sqlexception無法插入重複密鑰行
錯誤
SqlException: Cannot insert duplicate key row in object 'dbo.Users' with unique index 'UX_Users'. The duplicate key value is (1, [email protected]). The statement has been terminated.
SQL語句
string basestring = "student{0}@email.com";
string userName = "Student{0}";
using (Database dc = new Database())
{
dc.Connection.Open();
for (int i = 0; i < 400; i++)
{
string email = string.Format(basestring,i);
string sName = string.Format(userName, i);
User u = new User(){ Name = sName, UserName = email, InstitutionUniqueID = email, Email = email, CreationDate=DateTime.Now, InstitutionsID=1, GUID= Guid.NewGuid() };
dc.Users.InsertOnSubmit(u);
}
dc.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
}
這是我我得到錯誤:
dc.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
我正在使用linqpad進行測試。
如何定義''UX_Users''指數? – 2013-04-05 03:20:01