Forms Data Controls :: Object Cannot Be Cast From DBNull To Other Types?
Mar 10, 2010
There are two dropdowns for date (Fromdate and Todate) in my webpage and by default when the page loads for the first time the dropdowns loads with the last date (currentdate), if I select some previous date in Fromdate dropdown and reload the page then it displays runtime i.e.
Object cannot be cast from DBNull to other types.
Following code is written under GridView RowDataBound Event.
[Code]....
The error found at following line:
less7daysTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "less7days"))
If I comment this line then the error moves to next line till following line.
grt28daysTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "grt28days"))
I fruther want to inform that some columns in the grid are showing 0 if there is no record but I replaced 0 to - then some 0s replaced and some not. What is the reason?
View 30 Replies
Similar Messages:
Sep 9, 2010
Object cannot be cast from DBNull to other types. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types. Source Error:
[Code]....
Line 292:
Line 293: If DataBinder.Eval(e.Row.DataItem, "Casette") IsNot Nothing Then
Line 294: stcassette += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Casette"))
Line 295: End If
Line 296:
View 6 Replies
May 24, 2010
I have a webpage, i have a usercontrol in it , its name ispersonal1, i have tow Radiobutton in this usercontrol, the id of one of them ismale and the other one is female, it is obviously that each time we fill one of these radiobuttons and the other one will be null,in my database the type of these fields are bit , and they have allow null, i defined a property for my usercontrol like this:
public bool male
{
get
[code]...
View 2 Replies
Aug 2, 2010
here's my code...
select SUM(PETTYAMOUNT) AS tot FROM FINPETTY WHERE PETTYAMOUNT IS NOT NULL AND CENTER = '1'
if (drReadera.HasRows)
{
double totamta = Convert.ToDouble(drReadera["TOTALSUMA"]);
Label2.Text = String.Format("{0:N2}", totamta);
}
note: some of the pettyamount is null that's why i've got an error in page.
View 3 Replies
Sep 14, 2010
Case "System.Int32"
Return Convert.ToInt32(a) + Convert.ToInt32(b)
Object cannot be cast from DBNull to other types
View 3 Replies
Oct 31, 2010
here's my error...
Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.
here's my code.
double totald = Convert.ToDouble(drReaderdeduc["TAMT"]);
totaldeduc.Text = String.Format("{0:N2}", totald);
the problem is the query output is null but i convert.todouble so got an error... what is the best solution if the record is null?
View 2 Replies
Oct 1, 2010
Basically, what I did is that: I have a table in SQL database and some of data fields allow null. I built Objectdatasource through dataset. When I built update page using dataset. It generate the following error before showing the update page correctly. It seems I have issue to retrieve the null value from the database through using objectdatasource through dataset. Any suggestions?An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code
View 6 Replies
May 28, 2010
I am trying to write a table output from SQL database to a gridview/ Data List through an Object Data Source. I am a new starter and your help will be useful.
public List<Staff> GetStaff()
cmd.CommandType =
SqlConnection con =
new
SqlConnection(connectionstring);SqlCommand cmd =
new
[code]...
View 4 Replies
Jan 9, 2011
This has never happened before. It is not happening even in my visual studio. It is only happening on the live site. This never happened before on the live site either. I changed the master template but the change I made had nothing to do with the issue here. 3
[Code]....
Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Integer' is not valid.Source Error:
[Code]....
Line 25: <asp:DataList ID="DataList1" runat="server" DataKeyField="AParentID" DataSourceID="ObjectDataSource1" RepeatColumns="2" ShowFooter="False" ShowHeader="False" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" CellSpacing="0" CellPadding="0" ItemStyle-Width="225" Width="500px">
Line 26: <ItemTemplate>
Line 27: <asp:Image ID="Image1" runat="server" ImageAlign="NotSet" ImageUrl='<%# GetImage(Eval("AParentID")).ToString %>' />
Line 28: <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Indent(Eval("ACategory")).ToString() %>' NavigateUrl='<%# String.Format("articles_view_subcats.aspx?catid={0}",DataBinder.Eval(Container.DataItem,"ACategoryID")) %>' ForeColor='<%# GetFont(Convert.ToInt32(Eval("AParentID")))%>' Font-Size='<%# GetFontSize(Convert.ToInt32(Eval("AParentID"))) %>'></asp:HyperLink>
Line 29:
View 4 Replies
Nov 16, 2010
have a table that keeps track of customer data that is beyond the scope of the Membership Class, this table I am also using the Membership.CreateUser() generated user ID.When I use my INSERT statement however to create a new row in my table I keep getting the Specified cast is not valid error.This is my SQL Command (The ...refer to other fields)
Dim mySqlCommand As String = "INSERT INTO Customers (UserID, ...) VALUES (@UserID, ...)"
I send it to my Write_Database(mySqlCommand, Membership.GetUser(txtUserName.Text).ProviderUserKey, ...) function which then
I also tried sending he UserID as: CType(Membership.GetUser(txtUserName.Text).ProviderUserKey, SqlGuid)
Neither Works...both cause errors...My Write_Database Function is declared as follows:
Public Function Write_Database(ByVal MysqlQuery As String, ByVal UserID As System.Data.SqlTypes.SqlGuid, ...)
However Visual Studio shows that the error originates in the function calling code...
View 4 Replies
Mar 3, 2010
I need some help on the row updating for a gridview that i bind manually to a list, not using objectdatasource or sqldatasourcehere is my rowupdating. What i want to do for now is just get the values from the textboxes and I will store them to sting variables then I will call my update function and pass those as parameters. How do I get the data from the textboxes that the user just edited. I have the following but I am getting an error: "unable to cast object of type System.UI.LiteralControl to type System.UI.TextBox
View 5 Replies
Jul 7, 2010
Trying to explain this clearly. I have a dropdown listbox where user can select multiple names. These names are then selected/inserted into db table in a loop. Table is displayed in an editable gridview. I have a main sqldatasource1 on my aspx page with select/insert/update permissions, but because select command doesnt work with parameters of multiple values (or does it?), i resorted to using an alternative sql datasource in the codebehind in order to run the select query on the multiple values chosen from the dropdownlist to see if they were in my table.I now get this error when I go to select multiple names from the dropdown list
Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'.
View 2 Replies
Jan 28, 2010
I'm using vb and after i converted it from C# and tried to implement this:
[Code]....
I got an error that said: Unable to cast object of type 'System.Web.UI.WebControls.GridView' to type 'System.Web.UI.WebControls.LinkButton'.
And here's my code for the gridview table.
[Code]....
I've tried altering the code here and there but it never work
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
View 5 Replies
Mar 31, 2010
I wanted to delete the record from data but I receive this error "Unable to cast object of type 'System.Data.Linq.DataQuery`1[training_eval.Course]' to type 'training_eval.Course'.
Dim eval_sure = From ev In db.Evaluates Where ev.course_id = indexcourse Select ev.course_id
Dim del_course = From c In db.Courses Where c.Course_id = indexcourse
db.Courses.DeleteOnSubmit(del_course)
db.SubmitChanges()
View 4 Replies
Jan 5, 2010
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
[code]....
View 3 Replies
Apr 21, 2010
I am LINQ querrying against a datatable. However, I am unsuccessfull with catching null values. Here is my code that is giving me the following error.
[Code]....
I am checking to see if minperc is null. However to check that it still is trying to convert the value to double. Cant figure out a way around it. Here is the error: Cannot cast DBNull.Value to type 'System.Double'. Please use a nullable type.
View 1 Replies
May 7, 2015
I get this error when trying to export selected rows in gridview to pdf format
"Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'."
This my code below:
using (StringWriter sw = new StringWriter()) {
using (HtmlTextWriter hw = new HtmlTextWriter(sw)) {
gdfacture.Columns[0].Visible = false;
foreach (GridViewRow row in gdfacture.Rows) {
[Code] ....
View 1 Replies
Mar 5, 2011
I'm a noob to ASP.Net and I'm working on a simple project. In this project I have 2 drop down lists.In one drop down list I would like to select a panel web control and with the other select the background color for that panel.I can change the background color by calling the method Color.FromName() but selecting the panel object by casting it to a panel object from a string in a drop down list is stomping me.This is my starting code:
protected
void
Button1_Click(object[code].....
View 2 Replies
Jul 20, 2010
Can you iterate through a dictionary object that can contain a object and enum types
foreach(Dictionary<someObject, enumType> myDic in myObjects) {
if(enumType.myType == enumType.Type) {
do something here...
}
View 1 Replies
Mar 15, 2010
I'm building an application that uses GridView controls to display data to a page.In my editemplate i have following control
<div class = "divBox">
<div>Beginn/Zeit 2</div>
<div>
<asp:TextBox ID="tbBeginn2" CssClass="fSelect"
runat="server" Text='<%# Bind("beginnDatum2") %>'/>
BeginnDatum2 has datetime-Format in SQL-Server.
For the update i use an objectDatasource with following updateparameter
<asp:Parameter Name="beginnDatum2" Type="datetime" />
Now i'm trying to update this field but i have a problem when BeginnDatum2 must be null.
I get following (german) Errormessage:
SqlDateTime-Überlauf; muss zwischen 1/1/1753 12:00:00 AM und 12/31/9999 11:59:59 PM liegen.
And this is my paramter
Public Function UpdateSeminar(ByVal kursid As Integer, ByVal id As Integer, _
ByVal beginnDatum2 As DateTime, _
ByVal endeDatum2 As DateTime, _
cmd.Parameters.Add(New SqlParameter("@beginnDatum2", SqlDbType.DateTime))
If beginnDatum2 = Nothing Then
cmd.Parameters("@beginnDatum2").Value = DBNull.Value
Else
cmd.Parameters("@beginnDatum2").Value = DateTime.Parse(beginnDatum2)
End If
View 5 Replies
Mar 12, 2010
How can I cast from object to GUID in asp.net???
View 4 Replies
Dec 20, 2010
[Code]....
On the bold line I'm getting the following exeption:
The value for column 'ImageExtension' in table 'News' is DBNull.
View 2 Replies
Dec 17, 2010
I have built a dataset named Transaction_Time.I called it on Page_Load
Transaction_Time tranTme = new Transaction_Time();
put it in the session.
Session["Transaction"] = tranTme;
Then I call that session and cast to dataset.
DataSet dstTranTime = (DataSet)Session["Transaction"];
I got the following error.Unable to cast object of type 'Transaction_Time' to type 'System.Data.DataSet'.
[InvalidCastException: Unable to cast object of type 'Transaction_Time' to type 'System.Data.DataSet'.]
Transaction_Time.Page_Load(Object sender, EventArgs e) in c:InetpubwwwrootWilliam29_11_2010Transaction_Time.aspx.cs:47
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
It is OK for some other pages. But for some page, it doesn't.
View 2 Replies
Oct 8, 2010
I know that the problem is my field having NULL values. However, I don't know how to have it process the code even if the field have nullshere's my code:
[Code]....
View 5 Replies
Sep 16, 2010
I am binding SQL data to a GridView. The GridView's DataKeyNames property is set to the SQL column called "utID"
I know that within the SQL results, some of the utID values are NULL. After databinding to the GridView, I need to enumerate through the GridViewRows an read the DataKey values. However, when I try this I get the following error:
No default member found for type 'DBNull'. I am using the code below.
What object types are stored within DataKeys (I thought it was just integers or strings)
How to handle a NULL datakey value to prevent this error occurring?
I don't want to use Try Catch because it's too much of a 'hack'
[Code]....
View 6 Replies