/// <summary> /// 从datatable将数据导入 /// </summary> /// <param name="dataTable"></param> /// <returns></returns> public static int InsertIntoPropertyValueFromExcel(DataTable dataTable) { using (var context = new AnnonContext()) { try { foreach (DataRow dataRow in dataTable.Rows) { var propertyValue = new PropertyValue { PropertyID = Convert.ToInt32(dataRow["PropertyID"].ToString()), Price=Convert.ToDecimal(dataRow["Price"].ToString()), ValueCodeID = Convert.ToInt32(dataRow["ValueCodeID"].ToString()), ValueCode=dataRow["ValueCode"].ToString(), DeviceID=Convert.ToInt32(dataRow["DeviceID"].ToString()), PropertyValueType = dataRow["PropertyValueType"].ToString(), ValueDescription = dataRow["ValueDescription"].ToString() }; context.PropertyValues.Add(propertyValue); } return context.SaveChanges(); } catch (Exception e) { return -1; } } }
/// <summary> /// 插入属性值数据库 /// 可用 /// </summary> /// <param name="propertyID"></param> /// <param name="valueCodeId"></param> /// <param name="valueCode"></param> /// <param name="price"></param> /// <param name="valueDescription"></param> /// <param name="deviceId"></param> /// <param name="propertyValueType"></param> /// <returns></returns> public static int InsertIntoPropertyValue(int propertyID, int valueCodeId,string valueCode, decimal price, string valueDescription, int deviceId, string propertyValueType) { var propertyValue = new PropertyValue { PropertyID = propertyID, ValueCodeID = valueCodeId, ValueCode = valueCode, ValueDescription = valueDescription, DeviceID = deviceId, Price = price, PropertyValueType = propertyValueType }; using (var context = new AnnonContext()) { try { context.PropertyValues.Add(propertyValue); return context.SaveChanges(); } catch (Exception e) { return -1; } } }