private static void WriteConsole(DataTable dataTable) { Console.WriteLine("Csv file:"); Console.WriteLine(); Console.WriteLine(File.ReadAllText(FILE_NAME)); Console.WriteLine(); Console.WriteLine("Content of the refilled DataTable:"); foreach (DataRow?dataRow in dataTable.Rows) { if (dataRow is null) { continue; } const int padding = 15; for (int i = 0; i < dataTable.Columns.Count; i++) { object o = dataRow[i]; Console.Write(o switch { null => "<null>".PadRight(padding), DBNull dBNull => "<DBNull>".PadRight(padding), string s when s.Length == 0 => "\"\"".PadRight(padding), TimeSpan ts => ts.ToString("g", CultureInfo.InvariantCulture).PadRight(padding), _ => o.ToString()?.PadRight(padding) });
public void Update(Drazba drazba) { SqlConnection conn = DatabaseConnection.GetInstance(); SqlCommand command = null; using (command = new SqlCommand("UPDATE drazba SET popis=@popis,drazbaBezi=@drazbaBezi,car_id=@car_id where id = @id", conn)) { try { command.Parameters.Add(new SqlParameter("@id", drazba.ID)); command.Parameters.Add(new SqlParameter("@popis", drazba.Popis)); int autoId = dao.GetID(drazba.drazeneAuto); if (autoId == 0) { DBNull id = DBNull.Value; command.Parameters.Add(new SqlParameter("@car_id", id)); } else { int id = autoId; command.Parameters.Add(new SqlParameter("@car_id", id)); } command.Parameters.Add(new SqlParameter("@drazbaBezi", drazba.drazbaBezi)); } catch (Exception err) { Console.WriteLine(err.Message); } command.ExecuteNonQuery(); } }
public literal(DBNull n, DbType CoerceType) { type = DbType.Object; nullvalue = DBNull.Value; coerce = CoerceType; size = -1; }
// Delete the Otdelen by ID_Room. public int DeleteRecord(int ID_Manufacture, DBNull Parent_ID) { SqlConnection conn = new SqlConnection(_connectionString); SqlCommand cmd = new SqlCommand("DELETE FROM Manufacture WHERE ID_Manufacture = @ID_Manufacture", conn); cmd.Parameters.Add("@ID_Manufacture", SqlDbType.Int).Value = ID_Manufacture; int result = 0; try { conn.Open(); result = cmd.ExecuteNonQuery(); } catch (SqlException e) { // Handle exception. } finally { conn.Close(); } return(result); }
public static RdStaticArg BoxToServerStaticArg(object value) { if (value == null) { return(null); } return(value switch { sbyte x => new RdStaticArg(RdTypeName.@sbyte, x.ToString()), short x => new RdStaticArg(RdTypeName.@short, x.ToString()), int x => new RdStaticArg(RdTypeName.@int, x.ToString()), long x => new RdStaticArg(RdTypeName.@long, x.ToString()), byte x => new RdStaticArg(RdTypeName.@byte, x.ToString()), ushort x => new RdStaticArg(RdTypeName.@ushort, x.ToString()), uint x => new RdStaticArg(RdTypeName.@uint, x.ToString()), ulong x => new RdStaticArg(RdTypeName.@ulong, x.ToString()), decimal x => new RdStaticArg(RdTypeName.@decimal, x.ToString(CultureInfo.InvariantCulture)), float x => new RdStaticArg(RdTypeName.@float, x.ToString(CultureInfo.InvariantCulture)), double x => new RdStaticArg(RdTypeName.@double, x.ToString(CultureInfo.InvariantCulture)), char x => new RdStaticArg(RdTypeName.@char, x.ToString()), bool x => new RdStaticArg(RdTypeName.@bool, x.ToString()), string x => new RdStaticArg(RdTypeName.@string, x), DBNull _ => new RdStaticArg(RdTypeName.dbnull, ""), _ when value.GetType() is var type && type.IsEnum => BoxToServerStaticArg((int)value), _ => throw new ArgumentException($"Unexpected static arg with type {value.GetType().FullName}") });
public EquipmentRepairEntity(System.Data.DataTableReader dr) { this.pk_RepairID = Convert.ToInt32(dr["pk_RepairID"]); this.ContainerNo = Convert.ToString(dr["ContainerNo"]); this.Location = Convert.ToString(dr["Location"]); this.Damaged = Convert.ToBoolean(dr["Damaged"]); this.EstimateReference = Convert.ToString(dr["EstimateReference"]); this.fk_UserApproved = Convert.ToInt32(dr["fk_UserApproved"]); this.Line = Convert.ToString(dr["Line"]); this.RepMaterialAppr = Convert.ToDecimal(dr["MaterialAppr"]); this.RepMaterialEst = Convert.ToDecimal(dr["MaterialEst"]); this.RepLabourEst = Convert.ToDecimal(dr["LabourEst"]); this.onHold = Convert.ToBoolean(dr["onHold"]); this.RealeasedOn = DBNull.ReferenceEquals(dr["RealeasedOn"], DBNull.Value)? (Nullable <DateTime>)null: Convert.ToDateTime(dr["RealeasedOn"]); this.NVOCCId = Convert.ToInt32(dr["NVOCCID"]); this.Reason = Convert.ToString(dr["Reason"]); this.RepLabourAppr = Convert.ToDecimal(dr["RepLabourAppr"]); this.RepLabourBilled = Convert.ToDecimal(dr["RepLabourBilled"]); this.RepMaterialBilled = Convert.ToDecimal(dr["RepMaterialBilled"]); this.StockReturnDate = DBNull.ReferenceEquals(dr["StockReturnDate"], DBNull.Value) ? (Nullable <DateTime>)null : Convert.ToDateTime(dr["StockReturnDate"]); this.TransactionDate = DBNull.ReferenceEquals(dr["TransactionDate"], DBNull.Value) ? (Nullable <DateTime>)null : Convert.ToDateTime(dr["TransactionDate"]); }
public static string TypeValueToDbValueStatement(object?typeValue, bool quotedIfNeed, EngineType engineType) { if (typeValue == null) { return("null"); } Type type = typeValue.GetType(); EntityPropertyDef propertyDef = new EntityPropertyDef { Type = type, NullableUnderlyingType = Nullable.GetUnderlyingType(type), TypeConverter = null }; object dbValue = TypeValueToDbValue(typeValue, propertyDef, engineType); string statement = dbValue switch { //null => "null", //Enum e => e.ToString(), DBNull _ => "null", DateTime _ => throw Exceptions.UseDateTimeOffsetOnly(), DateTimeOffset dt => dt.ToString(@"yyyy\-MM\-dd HH\:mm\:ss.FFFFFFFzzz", GlobalSettings.Culture), bool b => b ? "1" : "0", _ => dbValue.ToString() ! }; if (!quotedIfNeed || statement == "null" || !SqlHelper.IsValueNeedQuoted(dbValue !.GetType())) { return(statement); } return(SqlHelper.GetQuoted(statement)); }
private void btnPost_Click(object sender, EventArgs e) { string Msg = "هل تريد بالتاكيد إعتماد جميع البطاقات المحددة؟"; if (new Dialogs.Dg_ComfirmMessage("إعتماد", Msg).MessageResult() == DialogResult.Yes) { string EntryDocNo = string.Empty; for (int i = 0; i < dgv_Reception.Rows.Count; ++i) { if (!DBNull.Equals(dgv_Reception["select", i].Value, null) && Boolean.Parse(dgv_Reception["select", i].Value.ToString()) == true) { EntryDocNo = dgv_Reception["Entry_doc_no", i].Value.ToString(); if (QuerySource == "pending") { Db.PostDlgReception(EntryDocNo, SharedParam.CurrentUser.UserID); } else { Db.PostReception(EntryDocNo, SharedParam.CurrentUser.UserID); } } } btn_Query_Click(sender, e); } }
public void Create(Drazba drazba) { SqlConnection conn = DatabaseConnection.GetInstance(); SqlCommand command = null; using (command = new SqlCommand("INSERT INTO drazba(popis,drazbaBezi,car_id) VALUES (@popis,@drazbaBezi,@car_id)", conn)) { int autoId = dao.GetID(drazba.drazeneAuto); if (autoId == 0) { DBNull id = DBNull.Value; command.Parameters.Add(new SqlParameter("@car_id", id)); } else { int id = autoId; command.Parameters.Add(new SqlParameter("@car_id", id)); } command.Parameters.Add(new SqlParameter("@popis", drazba.Popis)); command.Parameters.Add(new SqlParameter("@drazbaBezi", drazba.drazbaBezi)); command.ExecuteNonQuery(); command.CommandText = "Select @@Identity"; drazba.ID = Convert.ToInt32(command.ExecuteScalar()); } }
private void toolStripButton3_Click(object sender, EventArgs e) { if (grData.CurrentRow == null) { return; } bool rdism, rrem; if (DBNull.Equals(grData.CurrentRow.Cells["objDism"].Value, DBNull.Value)) { rdism = false; } else { rdism = (bool)grData.CurrentRow.Cells["objDism"].Value; } if (DBNull.Equals(grData.CurrentRow.Cells["onRemont"].Value, DBNull.Value)) { rrem = false; } else { rrem = (bool)grData.CurrentRow.Cells["onRemont"].Value; } if (rdism) { MessageBox.Show("Данное устройство снято с учета!", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (rrem) { MessageBox.Show("Данное устройство уже в ремонте!", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("Отметить выбранное устройство как нуждающееся в ремонте?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { SqlCommand cmd = new SqlCommand { Connection = new SqlConnection(Properties.Settings.Default.itInventorConnectionString), CommandType = CommandType.StoredProcedure, CommandText = "chkToRemont" }; cmd.Parameters.AddWithValue("@obNo", (int)grData.CurrentRow.Cells["objNo"].Value); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); int kod = (int)trPodr.SelectedNode.Tag; selOborudTableAdapter.Fill(selOborudDataSet.selOborud, kod); } }
public virtual void Test_Can_Convert_DBNull() { DBNull toConvert = DBNull.Value; StandardCLRConverter tConverter = new StandardCLRConverter(); object result = tConverter.ConvertToType(toConvert, typeof(bool)); Assert.IsNull(result); }
public override LocalDate?Parse(object value) { return(value switch { DBNull _ => null, DateTime dateTime => LocalDateTime.FromDateTime(dateTime).Date, _ => throw new ArgumentException($"Cannot convert {value.GetType()} to {typeof(LocalDate?)}") });
public void DBNull() { DBNull value = System.DBNull.Value; Type type = value.GetType(); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType, "GetXmlRpcType return DBNull as tStruct"); }
public void DBNull() { DBNull value = System.DBNull.Value; Type type = value.GetType(); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tInvalid, rpcType, "GetXmlRpcType return DBNull as tInvalid"); }
public override Instant?Parse(object value) { return(value switch { DBNull _ => null, DateTimeOffset dateTimeOffset => Instant.FromDateTimeOffset(dateTimeOffset), DateTime dateTime => Instant.FromDateTimeUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc)), _ => throw new ArgumentException($"Cannot convert {value.GetType()} to {typeof(Instant?)}") });
public static string ToString(this DBNull bNull, string resultStr) { if (DBNull.Value == null) { return(resultStr); } return(""); }
public SqlParameter CrearParametro(string nombre, DBNull valor) { SqlParameter p = new SqlParameter(); p.ParameterName = nombre; p.Value = valor; p.SqlDbType = SqlDbType.Int; return(p); }
public override LocalTime?Parse(object value) { return(value switch { DBNull _ => null, TimeSpan timeSpan => LocalTime.FromTicksSinceMidnight(timeSpan.Ticks), DateTime dateTime => LocalTime.FromTicksSinceMidnight(dateTime.TimeOfDay.Ticks), _ => throw new ArgumentException($"Cannot convert {value.GetType()} to {typeof(LocalTime?)}") });
static void Main(string[] args) { DBNull dbNull = DBNull.Value; Console.WriteLine(typeof(string).IsAssignableFrom(typeof(DBNull))); //False Console.WriteLine(dbNull is string); //False //Console.WriteLine((string)dbNull); // compile time error //Console.WriteLine(dbNull as string); // compile time error Console.ReadLine(); }
public void TestingDBNull(DBNull init) { ResetBois(); PrimitiveWriter.WriteValue(Writer, init); ResetStream(); var final = PrimitiveReader.ReadDbNull(Reader); final.Should().Be(init); }
internal static void WriteValue(BinaryWriter writer, DBNull dbNull) { if (dbNull == null) { WriteNullValue(writer); } else { WriteValue(writer, true); } }
internal object GetConstantValue(bool raw) { object obj = MdConstant.GetValue(this.GetRuntimeModule().MetadataImport, this.m_token, this.PropertyType.GetTypeHandleInternal(), raw); DBNull dbNull = DBNull.Value; if (obj != dbNull) { return(obj); } throw new InvalidOperationException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); }
/// <summary> /// Convert value to bytes and place in ByteContent at correct location /// </summary> /// <param name="field">Column information for the conversion</param> /// <param name="dbNull"></param> public void SetColumn(Field field, DBNull dbNull) { var chars = new char[field.Length]; for (var j = 0; j < field.Length; j++) { chars[j] = ' '; } Encoding.Default.GetBytes(chars, 0, chars.Length, ByteContent, field.DataAddress); Modified = true; }
public void IsTruthy_Check_DBNull() { // arrange DBNull value = DBNull.Value; // act bool result = Booleany.IsTruthy(value); // assert Assert.IsFalse(result); }
public void AgregarParametro(string p, DBNull dBNull) { Parametro parametro = new Parametro(); parametro.AgregarParametro(p, dBNull); if (this.Lista == null) { this.Lista = new List <Parametro>(); } this.Lista.Add(parametro); }
private object GetValue(bool raw) { object obj = MdConstant.GetValue(this.GetRuntimeModule().MetadataImport, this.m_tkField, this.FieldType.GetTypeHandleInternal(), raw); DBNull dbNull = DBNull.Value; if (obj != dbNull) { return(obj); } throw new NotSupportedException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); }
/// <summary>檢查DataColumn是否是空值(預設 DBNull.Value 回傳 = "")</summary> /// <param name="pDr">資料列</param> /// <param name="columnName">DataColumn名稱</param> /// /// <param name="returnStr">預設(DBNull.Value 回傳 = "")</param> /// <returns>string</returns> public string checkDataColumn(DataRow pDr, string columnName, string returnStr = "") { if (!DBNull.ReferenceEquals(pDr[columnName], DBNull.Value)) { string columnStr = pDr[columnName].ToString().Trim(); if (columnStr != "") { returnStr = columnStr; } } return(returnStr); }
private void btn_inverseSelect_Click(object sender, EventArgs e) { for (int i = 0; i < dgv_Reception.Rows.Count; ++i) { if (DBNull.Equals(dgv_Reception["select", i].Value, null) || Boolean.Parse(dgv_Reception["select", i].Value.ToString()) == true) { dgv_Reception["select", i].Value = false; } else { dgv_Reception["select", i].Value = true; } } }
public void ReadScalerDbNullReturnsNullObject() { DBNull scalerReturn = DBNull.Value; MockDatabaseFactory.SetScalerReturnValue(scalerReturn); var query = new SQLQueryScaler <string>(sqlString); var returnValue = queryHelper.RunScalerQuery <string>(query); Assert.IsNull(returnValue); VerifyLogging(sqlString); Assert.AreEqual(sqlString, MockDatabaseFactory.DbCommand.Object.CommandText); MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1)); MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Open(), Times.Exactly(1)); MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Close(), Times.Exactly(1)); MockDatabaseFactory.DbCommand.Verify(dbc => dbc.ExecuteScalarAsync(It.IsAny <System.Threading.CancellationToken>()), Times.Exactly(1)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { using (var db = new DBNull()) { User oldUser = db.Users.Find(user.Id); oldUser.Firstname = user.FirstName; oldUser.LastName = user.Last.Name; db.SaveChanges(); } } return(View(user)); }
#pragma warning restore 618 // Allow internal extenders to avoid creating the hashtable/arraylist. internal NameValueCollection(DBNull dummy) : base(dummy) { }
/// <summary> /// Writes a 'null' text as a value. /// It requires to be put inside an object. /// </summary> public void WriteMember(string name, DBNull value) { WriteMemberInternal(name, JSonReader.NullString, false); }
// Allow internal extenders to avoid creating the hashtable/arraylist. internal NameObjectCollectionBase(DBNull dummy) { }
/// <summary> /// Writes a 'null' value. /// It can be used only as an array element or value for object member. /// </summary> public void WriteValue(DBNull value) { WriteValueInternal(JSonReader.NullString, false); }
static DBNull() { Value = new DBNull(); }
public void WriteValue(DBNull value) { throw new NotImplementedException(); }
public bool IsEmpty(DBNull x) { return false; }
public void WriteMember(string name, DBNull value) { throw new NotImplementedException(); }
/*public void Add(string parameter, Guid value) { Add(new OracleParameter(parameter, OracleDbType.)).Value = value; }*/ public override void Add(string parameter, DBNull value) { Add(new OracleParameter(parameter, DBNull.Value)).Value = value; }
public Table(string fileName) { string[] lines = File.ReadAllLines(fileName); List<Value[]> table = new List<Value[]>(lines.Length); for (int i = 0; i < lines.Length; i++) { string[] columns = lines[i].Split(','); Value[] values = new Value[columns.Length]; for (int j = 0; j < columns.Length; j++) { string cell = columns[j].Where(x => x != ' ' && x != '\t').Aggregate("", (x, y) => x + y); int intValue; double realValue; if (Int32.TryParse(cell, out intValue)) values[j] = new DBInteger(intValue); else if (Double.TryParse(cell, out realValue)) values[j] = new DBReal(realValue); else if (cell == "NULL") values[j] = new DBNull(); else values[j] = new DBString(cell); } table.Add(values); } Rows = table; }