Tuesday 15 September 2015

sql server - C# function to cast multiple datarow values as null if dbnull is detected -


My Linux-to-SQL program is returning a lot of values ​​from my SQL Server database, some of which may be null

If the DataTable column is inserted as a string, this is not a problem, though when it is inserted in decimal form, when I get an error message Can not be decimal.

I need to know how I can manage them effectively when keeping my code organized.

  // DataTable DataTable.dt = create new datatellas (); Dt.Columns.add ("deal", typef (string)); Dt.Columns.add ("value", type (decimal) - typef (dbbull)); // Create LINQ query by var query = quer select new in table {quer.deal_id, quer.price};   

Before I join the table, I change my door:

  var datarows = query.Select (r = & gt; {var row = Dt.NewRow (); line ["deal"] = R.Diggle_Aud; line ["value"] = R.Pricease;}   

Now to make sure that my Dataro Faucet I can handle it, I can just do it, but it is not necessary.

But in the decimal field I have to do this:

  if (r.price == DBNull.Value) {line ["value"] = zero;}   

Now what do I have to do about 50 of these if I make a comment per table What can I do? Can I pass it in a function?

To accept DBNull value, you can set your DataColumn :

  // datatable dataTableDT = new datatyll (); dt. Columns.add (new data columns ("deal", typef (string)); Dt.Columns.add (create new data columns ("value", typef (decimal)) {AllowDBNull = true}; // Create LINQ query by var query = quer select new in table {quer.deal_id, quer.price};    

No comments:

Post a Comment