//修改 DataGrid public void adddiary(cdiary diary) { string strsql; const string DIARY = "DIARY"; const string contacts = "CONTACTS"; string id; if (diary == null) { reminder = "添加日记,添加的日记空"; return; } //if name==null //insert name strsql = $"{usesql} SELECT ID FROM {contacts} WHERE NAME='{diary.CONTACTSID}';"; id = write(strsql); if (string.IsNullOrEmpty(id)) { strsql = $"{usesql}{line}insert into {contacts}(name){line}values('{diary.CONTACTSID}') SELECT @@IDENTITY AS Id;"; id = write(strsql); } strsql = $"{usesql}{line}insert into {DIARY} (Mtime,PLACE,INCIDENT,CONTACTSID){line}values('{diary.MTIME}','{diary.PLACE}','{diary.incident}','{id}');"; write(strsql); //错 }
public void ddiary(cdiary diary) { string strsql; const string DIARY = "DIARY"; strsql = $"{usesql}{line}DELETE FROM [dbo].[{DIARY}] WHERE id='{diary.id}';"; write(strsql); }
public void newdiary(cdiary diary) { string name = diary.CONTACTSID; const string contacts = "CONTACTS"; string strsql; string id; strsql = $"{usesql} SELECT ID FROM {contacts} WHERE NAME='{name}';"; id = write(strsql); if (string.IsNullOrEmpty(id)) { strsql = $"{usesql}{line}insert into {contacts}(name){line}values('{name}') SELECT @@IDENTITY AS Id;"; id = write(strsql); } string DIARY = "diary"; strsql = $" UPDATE [dbo].[{DIARY}] SET [MTIME] = '{diary.MTIME}' ,[PLACE] = '{diary.PLACE}' ,[INCIDENT] = '{diary.incident}' ,[CONTACTSID] = '{id}' WHERE id='{diary.id}'"; write(strsql); }