ADO.NET :: LINQ Over DataTable Null Decimal Field ?
Feb 9, 2011
I'm having a spot of trouble figure out how to write my linq query so that is allows a decimal field in my datatable to be null
Right now I have this:
[Code]....
But it's not working. The error I am getting is: Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type.so how do I get it to allow program_ar_id to be null?
View 2 Replies
Similar Messages:
Jun 16, 2010
I have req where i have to pass null value,if value coming from db is null.Problem here is the field datatype is 'Decimal' so all the time even though value is null ,its passing as zero.How can I pass a null value to decimal field in C#.
FieldValue = (reader["Field"] ==
DBNull.Value) ?
Convert.ToDecimal(null) :
Convert.ToDecimal(reader["field"]);
What I want is ,Field value will get null value assigned not zero.
View 4 Replies
Aug 27, 2010
I am converting my datatable to LISt using LINQ how do I handle nulls coming from database
List<Port> portDetails = new List<Port>();
DataTable dt = ds.Tables[0];
portDetails = (from q in dt.AsEnumerable()
select new Port
{
PortCode = q.Field<string>("Code"),
ExtCode = q.Field<string>("Nb"),
Name = q.Field<string>("Name"))
}).ToList();
In the above query if Code is null I do not want property portcode to be set to the value it should only set if it is not null or not blank
PortCode = q.Field<string>("Code"),
What should be syntax
I was trying somethign like this which doesnt work
Portcode = q.Field<bool>("Code") == null ? null : q.Field<bool>("Code")
View 1 Replies
May 7, 2015
When I am Exporting CSV Using Reader,Here Attached Coding for your reference,
PrecisionColumns = New String() {"Salequantity", "Salevalue", "Purchasequantity", "Purchasevalue", "Stockvalue"}
If Trim(Rdr.GetValue(I).ToString() <> "") Then
csv += Format(CDbl(Rdr.GetValue(I).ToString()), "0.00").Replace(",", ";") + ","c
End If
csv += vbCr & vbLf
Response.Write(csv)
... ...
I get precision in CSV file ,but when i open the csv file in excel Precision not showing, how to show precision on excel sheet...
View 1 Replies
Nov 6, 2010
i am using the following in a stored procedure.
[code]....
[Code]....Handling NULL...Field not updating when NULL?
View 3 Replies
Apr 1, 2011
I have a DetailsView on the page and I have made one of the fields a TemplateField. In the EditItemTemplate and InsertItemTemplate I have a DropdownList that is databound to a table in my Sql Server database. I wanted to add an initial value to the DropdownList
namely "- select -" .
I set the AppendDataBoundItems property to true and added the initial value as a ListItem.Markup of the DropdownList
<asp:DropDownList ID="DropDownList_HP" runat="server"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_HP" [code]...
This works fine for new input. The problem is however that the database already has records that were entered through a Windows Application and many of these records has a null value in this field and exceptions are thrown when I tried to open these records
and the system tried to set the SelectedValue of the DropdownList.After some more searching I found this help
http://msdn.microsoft.com/en-us/library/ms366709.aspx
So I changed the ListItem in the DropDownList markup to the following:
<asp:DropDownList ID="DropDownList_RefHospDV4" runat="server"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_RefHosp" [code]...
This now solved the problem of opening a record where the value is null in the database, BUT now the RequiredFieldValidator is not validating anymore to make sure that a databound item is selected for this field and not the initial value "- select -". So basically now it is not checking anymore to see if valid input has been entered for the DropDownList and it accepts "- select -" thus it acts as if the field is not a required field anymore.
In short what is required is that I want to make sure that the user enters a valid selection in the DropDownList, but it must also cater for old records that do not have this field entered yet so that those old records can be opened in the DetailsView .Opening Old records (with null in that field):When these old records are opened in the DetailsView the DropDownlist should show "- select -" when the value in the database is null.
Saving records (old or new records):When saving the record in Insert mode or Update mode the RequiredFieldValidator should show that a valid input is not selected if the DropDownList is still on "- select -".
View 1 Replies
Feb 2, 2010
I am getting a DataTable from query against AS400 database. The field that clearly contains birth dates is interpreted as decimal. I am having trouble even converting it to string.
View 1 Replies
Feb 2, 2010
how to get my perclock field to show a decimal? For some reason I keep getting '0'.
View 3 Replies
Nov 7, 2013
I have qi1 decimal field ... coming error in line ...
txtCostPrice = Convert.ToInt32(((TextBox)GridView2.Rows[i].FindControl("txtcostprice")).Text);
my code
public void savedata() {
con = new SqlConnection(dbcon);
con.Open();
int txtCostPrice = 0;
//int txtSellPrice = 0;
int Primarykey = 0;
[code].....
View 1 Replies
Mar 6, 2010
when updating a decimal field in a GridView all is fine when using e.g. "2.3" ("." to separate the fraction!)
However, when using "2,3" I get e formatstring exception!
I tried "regularExpressionValidator/RequiredFieldvalidator" but did not succeed! Tried also with FormatString like {0:n}.....
Questions:
is this controllable by "Culture / UICulture" in web.config (played with it without success!
How do I best check for correct input i.e. force "." as separator
Can I use the "DataFormatString" property for the appropriate GridView field (like {0:n}) ......
[code]....
View 1 Replies
Jan 6, 2010
In Microsoft Access Database Form, I have a series of five fields. I would like to set up a field that is equal to the first field unless that field is null or 0. Then I want the field to be equal to the second field unless that field is null or 0, continuing the same way through the five fields. Being a newb, I have no idea how.
View 1 Replies
Dec 22, 2010
I am making a website to store invoices so i can mail them to clients. So i got a table for clients, invoices and one with invoice products/services. When an invoice has no products/services added to them and it returns null i get the error "the null value cannot be assigned to a member with type System.Decimal which is a non-nullable value type."
I just started with linq. Before i always used mysql. Mostly i just had to call data from 1 table so forgive me if my linq query isn't really correct.
Dim invoices = From i In db.invoices _
Group Join p In db.products On i.id Equals p.invoiceId Into invoiceProducts = Group _
Select New With {i.client.naam, i.titel, (From iP In invoiceProducts Select iP.prijs).Sum}
i show the client's name, the title of the invoice and the total amount the clients will need to pay for products and services.
View 1 Replies
Jan 21, 2010
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
View 8 Replies
Aug 22, 2012
i hav one data table in which some decimal values are up 6 decimal places.. im trying to bind that Data table to DataGridView while binding i want to round decimal values up to two decimal palces here is my code
dt.Columns.Add("Orderid", typeof(string));
dt.Columns.Add("tagnumber", typeof(string));
dt.Columns.Add("Minimum Value", typeof(string));
dt.Columns.Add("Maximum Value", typeof(string));
int count = ds.Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
[code]...
hows hould i round up while binding..?
View 1 Replies
May 7, 2015
I was read your post: "Export GridView to Excel in ASP.Net with Formatting using C#" and is very useful. That code works perfect. But I need create a new format for a specific column in my sheet before to export it. For example:My DataTable have a column with decimal numbers and I'm trying reduce the tenths for each number.I want this: 2,874444 ----> 2,87 for a specific range. In this case I need it for all numbers in the column 13 or well said for the Column called N in Excel. Only reduce two tenths.
I used:
xlWorkSheet.Range["N"+h,"N"+h].NumberFormat = "0.00";
And no works (h is for rows, N is the column. Into a foreach).
View 1 Replies
Mar 10, 2011
I have a data table say i have a column like x which is primary key so i should get the row where this x values in empty.
View 2 Replies
Aug 6, 2010
My application has a three tier architectute
UI Business DataAccess Here, I'm calling a SP from Data Access layer which will populate a DataTable and return the DataTable back to Business. My source code is like below.
[Code]....
Here, when I set debugpoint I can see the DataTable is getting populated by the data so my
sp idreturning the data. there is no issue with the sp and dataaccess layer method. The problem lies below on my business layer. The source code is like below.
[Code]....
View 2 Replies
Apr 6, 2010
I'm trying to execute this statement every minute with SQL Agent, I have it set up as a job:
[Code]....
It's trying to update a column which data type is set to decimal. Just so you know what I really need out of it, here is an example:
[Code]....
The answer of which should add on 0.5 to the original value. If I were to use the increase value of 60 which then becomes 60/60 it will work.I'm dividing by 60 because the increase value is per hour so I make it smaller to get per minute value. Why is it doing this?
View 2 Replies
Mar 3, 2010
Some values are returning 2.0 but I need it to be 2.00 as this is a money value that is displayed to the web page.
I am doing:
Math.Round(value, 2);
Is there a way to force it to 2 numbers after the decimal?
View 3 Replies
Feb 13, 2010
I have a DataTable for which a PrimaryKey constraint has been set to be a combination of an integer column and a datetime column. When I try to 'Find' a row by saying,
dtFunds.Rows.Find(iContainerIndex)
I get a null value. iContainerIndex has been defined as an object array of size 2 with the integer ID and date values in it.
When I set a breakpoint in my code, I see that the very same values are present in the datatable.
If I try to execute, DataTable.Select() method with the integer column filter, I get a result - but returns no result when called with the date column filter.
What am I doing wrong here? The very same DateTime value is present in the datatable.
View 1 Replies
May 5, 2010
I need a validation regex for decimal. It should allow upto 5 digits after decimal.
Allow:
1
1.0
12.0
12.01
123.01
1,123.01
1,123.013
21,123.01234
3,21,123.01234
How Can I do regex for this?
View 4 Replies
Oct 7, 2010
Since I am not using a DataSourceId at the markup I am having to create my own Sorting handler. I found a sample on MSDN but the variable 'dataTable' always returns null why?
[Code]....
and here is how I am feeding the DataGrid:
[Code]....
View 2 Replies
Jan 31, 2011
public
partial class
_Default : System.Web.UI.Page [code]....
in above code when i click button1 DTNav is null .........
View 1 Replies
Feb 10, 2011
Many times I need to manipulate with DataTable after I get data from database using adapter.Fill(table).
Usually I calculate data in DataTable by using loops. But I know that there is simpler way using LINQ. I know some basics about that just for strongly typed objects.I can't find how to do this with DataTable that is not strongly typed. How could I get all DataRow or Filtered DataTable (not just value for the field) from table for that conditions:
- where the specified field of the table contans MAX/MIN/AVG value,
- where the specified field of the table equals to some value.
View 1 Replies
Sep 20, 2010
I got the following query to group the table. I am wondering how to add a subtotal record with anonymous type.
string prevOriginator = string.Empty;
var oOriginator = (from I in dtIssue.AsEnumerable()
group I by new {RaisedBy = I.Field<string>("RaisedBy"), ItemType = I.Field<string>("ItemType")} into grp
[code]...
View 1 Replies