public int?MergeUser(int?userId, string username, int clientId) { var id = -1; string query = ""; //NEW if (userId == null) { // made changes here to string Removed Table before Users replaced [] to () replaced empty userID to NULL at Values(...) placed backslashes query = String.Format("INSERT INTO Users (userId, username, clientId) VALUES (NULL,\"{1}\", {2}); SELECT last_insert_rowid() FROM Users", userId, username, clientId); } //UPDATE else { // escaped quotes \" extraneous ' removed - added missing set clientId SET query = String.Format("UPDATE Users SET username=\"{0}\", clientId = {2} WHERE userId={1}", username, userId, clientId); } var ds = _sqliteConfig.ExecuteQuery(query); if (ds.HasData()) { //id = ds.Tables[0].Rows[0]["clientId"].ToInt(-1); id = ds.Tables[0].Rows[0][0].ToInt(-1); } return(id); }
public int?MergeClient(int?clientId, string clientName) { var id = -1; string query = ""; //NEW if (clientId == null) { // escaped quotes \" extraneous Table text removed - [] to () - replaced empty clientId to NULL at Values(...) query = String.Format("INSERT INTO Clients (clientId,clientName) VALUES (NULL,\"{1}\"); SELECT last_insert_rowid() FROM Clients", clientId, clientName); //query = "Select * from users"; } //UPDATE else { // escaped quotes \" extraneous ' removed query = String.Format("UPDATE Clients SET clientName=\"{0}\" WHERE clientId={1}", clientName, clientId); } var ds = _sqliteConfig.ExecuteQuery(query); if (ds.HasData()) { //id = ds.Tables[0].Rows[0]["clientId"].ToInt(-1); id = ds.Tables[0].Rows[0][0].ToInt(-1); } return(id); }