"DBNULL" to the type "string" forced conversion is invalid & how to write null to the parameters of SQLC

xiaoxiao2021-03-06  41

The forced conversion from type "dbnull" to type "string" is invalid. This is often encountered. Some people recommend as follows: if not ds.tables ("file"). Rows (0) .Item (5) .gettype Is system.dbnull.value.gettype kilover, if each field is made, it is a bit too much. Some people suggest it directly in the SELECT statement: SELECT NAME, ISNULL (Memo, ') as memo from xxx Finally, I feel A better way is: You will go directly to Tostring (). TextBox1.text = ds.tables (0) .ROWS (ROWNUM) .Item ("e_edate"). Tostring (); prompting you to force the conversion invalid, you give it direct conversion. I would like to ask: When the parameter is a date type, when the date is empty, how to assign the parameter! To write the Null date into the database! ! Thank you! ! -------------- RE1: The NULL field for any type is: dbnull.Value;

--------------- RE2: The upstairs can also be replaced with DateTime.minvalue. --------------- RE3: Thank you very much!

To eBoywy: Solve the problem that stored in the database with DBNULL.Value, but when reading data from the DataSet to TextBox, write TextBox1.Text = ds.tables (0). Rows (Rownum). Item ("e_edate"), will prompt the error "From the type" dbnull "to the type" string "forced conversion is invalid." To make a judgment: if ds.tables (0) .rows (rownum) .Item ("e_edate ") Is DBNULL.VALUE THEN ELSE Med_EDate.ctltext = .Idate (" e_edate ") &" "End if, is there a simpler way! If each field makes such a judgment, it is a bit too much.

To zhanqiangz: Your assignment method error: "Unpredited" System.Reflection.targetInvocationException "type exception appears in Mscorlib.dll. Other information: The target call is exception.", please don't know What does this mistake mean?

Thank you --------------- RE4: You go directly to TOSTRING (). TEXTBOX1.TEXT = ds.tables (0) .ROWS (ROWNUM) .Item ("e_edate"). Tostring ();

Prompt you to force the conversion is invalid, you will directly switch it.

转载请注明原文地址:https://www.9cbs.com/read-72314.html

New Post(0)