dbnull

Check if Eval(“VALUE”) is null

倖福魔咒の 提交于 2019-12-13 04:35:54
问题 Quite new to C# I need to cast a value to add minutes to a date but it can be null. Here's how I do : if(Eval("DUREE") != DBNull.Value) { var duration = Convert.ToInt32(Eval("DUREE")); var date = Convert.ToDateTime(Eval("DATE")); var dateAsString = Convert.ToString(date.AddMinutes(duration)); DataBinder.Eval(Container.DataItem, dateAsString, "{0:HH:mm}") } else { " - " } Here the error I get : DataBinding : 'System.Data.DataRowView' doesn't comport properties called : '17/04/2014 13:30:00'.

Object initializing with db null check

风格不统一 提交于 2019-12-13 03:59:26
问题 I am trying to initialize an object with data from database return in a dataset as below: Class Pdf Public FileId As Integer Public AccountNumber As Integer Public DateSaved As DateTime Public FileName As String Public DateImported As DateTime Scenerio 1 I can intialize the object like this: Dim pdf = New Pdf With {.FileId = ds.Tables(0).Rows(i)("fileid"), .AccountNumber = ds.Tables(0).Rows(i)("accountnumber"), .DateSaved = ds.Tables(0).Rows(i)("datesaved"), .FileName = ds.Tables(0).Rows(i)(

LINQ to Dataset DBNULL problem / null reference exception

爷,独闯天下 提交于 2019-12-13 03:45:41
问题 I have the following LINQ query which always results in an error when my "Remark" column in dtblDetail is null, even though I test if it is NULL. var varActiveAndUsedElementsWithDetails = from e in dtblElements join d in dtblDetails on e.PK equals d.FK into set from d in set.DefaultIfEmpty() where (e.ElementActive == true) select new { ElementPK = e.PK, Remark = d.IsRemarkNull() ? null : d.Remark }; The error message was: "The value for column 'Remark' in table 'dtblDetails' is DBNull." After

Implicit conversion from data type nvarchar to varbinary(max) is not allowed

杀马特。学长 韩版系。学妹 提交于 2019-12-12 10:29:29
问题 I get this exception when I try to insert a DBNull.Value into a nullable varbinary(max) field: Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. Thats my code: insertCMD.Parameters.AddWithValue("@ErrorScreenshot", SqlDbType.VarBinary).Value = DBNull.Value; I know there exist duplicate questions on SO, but I do NOT use any String like the others do. What do I wrong? UPDATE: using (var insertCMD = new SqlCommand("INSERT

SQLDataReader does not identify the empty columns

扶醉桌前 提交于 2019-12-12 02:49:48
问题 So, I have a function which reads the result of a query that is used later on the program as it follows: connection.Open(); int combination; using (SqlCommand com1 = new SqlCommand()) { com1.Connection = connection; com1.CommandText = "select FinalComboId from relationTable where sourceCombo=@source and destinationCombo=@destination"; com1.Parameters.Add(new SqlParameter("@source",combo.ToString() ?? "")); com1.Parameters.Add(new SqlParameter("@destination", destination ?? "")); SqlDataReader

How to create a list for a ComboBox that allows DBNull?

核能气质少年 提交于 2019-12-12 01:54:40
问题 How to create a list for a ComboBox that allows DBNull? I tried int? But int? is not the same as DBNull and the combobox does not work with the null value. My datagridview combobox, needs DBNull . I did: var machineComboList = this.eMDataSet1.Machines.Select(row => new { Key = (int?) row.MachineID, Value = row.Description }).ToList(); int? nullValue = DBNull.Value; machineComboList.Add(new { Key = nullValue, Value = "All" }); I want to put a DBNull value into "Key". Using int? does not work.

Getting SCOPE_IDENTITY from SQL Server on Insert

馋奶兔 提交于 2019-12-11 12:32:03
问题 I guess it is too late and I'm too tired to see what I'm doing wrong. Here is what I'm trying: int imageId = imageDal.AddImage(new SqlParameter[] { new SqlParameter("@IMAGE_ID", SqlDbType.Int, Int32.MaxValue, ParameterDirection.Output, true, 0, 0,"IMAGE_ID", DataRowVersion.Current,DBNull.Value), new SqlParameter("@IMAGE", SqlDbType.Image, 11, ParameterDirection.Input, true, 0, 0,"IMAGE", DataRowVersion.Current,image) }); public int AddImage(SqlParameter[] spParams) { SqlHelper.ExecuteNonQuery

How to find out which Columns are nullable in a DataTable?

懵懂的女人 提交于 2019-12-11 07:08:25
问题 Is there a way to find out which columns are nullable in a DataTable? I know that there is a proprety: DataColumn.AllowDBNull, which can be set to true or false in the design mode of the DataSet, but I would like to have this information directly from the database. I am having a DGV populated with values from a MySQL database and have bound the DataSource of the DGV to a DataTable. 回答1: As a solution I decided to retrieve the Columns Schema of the Database and from there assign which Collumns

Informix (C#): How do I properly set/unset a blob field?

别说谁变了你拦得住时间么 提交于 2019-12-11 03:03:17
问题 IBM Informix SDK: Statement: Update mytable set myblobcolumn = ? where myid = 1; using (IfxConnection conn = GetIfxConnection()) using (IfxCommand cmd = new IfxCommand(updateSql, conn)) { var param = new IfxParameter("myblobcolumn", IfxType.Blob) { IsNullable = true }; cmd.Parameters.Add(param).Value = DBNull.Value cmd.ExecuteNonQuery(); //ERROR [HY000] [Informix .NET provider][Informix]Illegal attempt to use Text/Byte host variable. } If I update it with another IfxBlob object it works fine,

DBNull check for ExecuteScalar

荒凉一梦 提交于 2019-12-10 15:18:41
问题 The stored procedure for command can return null.Is it correct way to check if the returned value is null or should I also check that obj is null? object obj = command.ExecuteScalar(); int id = -1; if (DBNull.Value == obj) { id = Convert.ToInt32(obj ); } 回答1: You probably want to change your if-statement to if (obj != null && DBNull.Value != obj) { ... } Right now you're trying to convert if obj == DBNull.Value . 回答2: If there is no result your query can return null , so in the general case