private bool Add(Fact obj, out string message) { message = string.Empty; bool result = false; if (this.session != null && this.session.Connection != null && this.session.Connection.State == ConnectionState.Open) { SqlCommand command = new SqlCommand(string.Empty, this.session.Connection); SQLCommandBuilder builder = new SQLCommandBuilder(TableNameWithScheme); builder.AddParameter(tableFieldCREATION_DATE, "@p_create_date"); command.Parameters.AddWithValue("p_create_date", obj.CreationDate); builder.AddParameter(tableFieldNUMBER, "@p_number"); command.Parameters.AddWithValue("p_number", GetNextNumber()); FillCommandBuilder(builder, command, obj); builder.FinishString = "SELECT @@IDENTITY AS 'Identity'"; command.CommandText = builder.GenerateInsertText(); try { object value = command.ExecuteScalar(); if (value != null && value != DBNull.Value) { try { int id = Convert.ToInt32(value); obj.Id = id; result = true; } catch (Exception ex) { result = false; message = ex.Message; } } } catch (Exception ex) { result = false; message = ex.Message; } } return(result); }
private bool Add(Author obj, out string message) { message = string.Empty; bool result = false; if (this.session != null && this.session.Connection != null && this.session.Connection.State == ConnectionState.Open) { SqlCommand command = new SqlCommand(string.Empty, this.session.Connection); SQLCommandBuilder builder = new SQLCommandBuilder(TableNameWithScheme); FillCommandBuilder(builder, command, obj); builder.FinishString = "SELECT @@IDENTITY AS 'Identity'"; command.CommandText = builder.GenerateInsertText(); try { object value = command.ExecuteScalar(); if (value != null && value != DBNull.Value) { try { int id = Convert.ToInt32(value); obj.Id = id; result = true; } catch (Exception ex) { result = false; message = ex.Message; } } } catch (Exception ex) { result = false; message = ex.Message; } } return(result); }