public EndPointInfo GetOrCreate(string EndPoint, IJetTransaction jetTransaction) { EndPointInfo resultInfo = null; OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); oleDbCommand.CommandText = string.Format("SELECT [ID] FROM {0} WHERE [EndPoint]=@EndPoint;", _EndPointTable.TableName); oleDbCommand.Parameters.AddWithValue("@EndPoint", EndPoint); using (OleDbDataReader reader = oleDbCommand.ExecuteReader(CommandBehavior.SingleRow)) { if (!reader.HasRows) { resultInfo = this.Add(EndPoint, jetTransaction); } else { reader.Read(); int id = Convert.ToInt32(reader["ID"]); resultInfo = new EndPointInfo(id, EndPoint); } } return resultInfo; }
private EndPointInfo Add(string EndPoint, IJetTransaction jetTransaction) { EndPointInfo resultInfo = null; OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); oleDbCommand.CommandText = string.Format("INSERT INTO [{0}] ([EndPoint]) VALUES (@EndPoint);", _EndPointTable.TableName); oleDbCommand.Parameters.AddWithValue("@EndPoint", EndPoint); oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); oleDbCommand.CommandText = string.Format("SELECT @@IDENTITY FROM [{0}];", _EndPointTable.TableName); oleDbCommand.CommandType = CommandType.Text; int newId = (int)oleDbCommand.ExecuteScalar(); resultInfo = new EndPointInfo(newId, EndPoint); return resultInfo; }