Unable to cast object of type 'System.DBNull' to type 'System.String'

I have received the following error when I am logged in as administrator.  I wanted to test the load event feature.  Allows me to load and save new event.  I can view event on location view page but when I try to link to "list or calender" view I receive this error "Unable to cast object of type 'System.DBNull' to type 'System.String'.  Debug highlights the <asp:HyperlinkID as errored line.

Any assistance would be greatly appreciated

Brian

 

<DayEventTemplate>

<div style="padding: 3px;">

<asp:HyperLink ID="HyperLink1" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%# "Events_view.aspx?Eventid=" + Convert.ToString(Eval("ID"))%>'

ToolTip='<%# SharedRoutines.truncate((string)Eval("description")) %>' /></div>

</DayEventTemplate>

</ec:EventCalendar>

</div>

0
ONPADREISLE
5/18/2007 12:55:34 PM
asp.net.club-site-starter-kit 1219 articles. 0 followers. Follow

3 Replies
3072 Views

Similar Articles

[PageSpeed] 4

 Make sure you're not returning null values from the data base or at least handling them appropriately.


German Afanador
0
Trebolin
5/18/2007 2:16:21 PM

In your event, you had a null value for the description. This is not allowed. I recommend using the updated starter kit (www.codeplex.com/clubstarterkit)


Zack Owens

Coordinator for the ClubStarterKit (Open Source)
http://codeplex.com/clubstarterkit
0
zowens
5/18/2007 7:03:00 PM

Changed the referenced "ID" in Convert.ToString"  to not allow nulls in the description field in the Club.mdf table/events file.  Issue resolved;

Thank you for your help

0
ONPADREISLE
5/19/2007 4:07:06 AM
Reply:

Similar Artilces:

System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'
Hello , I am a data table with null able Columns.I am not able to catch the value for DBNull. I did set a value to be returned as empty in dataset. Here is the code where i am trying to catch.1 public List GetStores() 2 { 3 List tmpStore = new List(); 4 StoresService.shopDBDataSet.StoresDataTable stores = 5 storesService.GetStores(); 6 for (int i = 0; i < stores.Count ; i++) 7 { 8 Store store = new Store(); 9 store.StoreID = stores[i].StoreID...

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Hi there, If I add a new event and leave the description field empty the StarterKit seems to throw a big wobbly over the null values in my DB (SQL2000). Have I made a mistake in the installation or something? The problem lies in this line: SharedRoutines.truncate((string)Eval("description")) because description is Null. I want to sort this in this line and I don't want to reply on validators? This is a known issue reported in the Identified Bugs and Fixes for the ClubSite Starter Kit post. I don't think there is one definitive answer. Search on your error message and you'll fin...

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Hi i have the following which is meant to check if an image is available and if it isnt it should show a default image however, it gives me this error whenever the image is null in the database. This is the function which returns the error;protected string FormatImageUrl(object url) {if ((url != DBNull.Value) && (url != null) && (url.ToString().Trim().Length > 0)) { //if (File.Exists(url))return (url.ToString().Trim()); } else {return "~/images/default.gif"; } } Hey,Doesn't seem to pass the dbnull check.  Try to do:  if ((!DBNull.Valu...

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Hi i get the following error, Unable to cast object of type 'System.DBNull' to type 'System.String'.  A generic image is meant to appear when no image is found in the database for a particular product, this is how the code is laid out;protected string FormatImageUrl(string url) {if (url != null && url.Length > 0) { //if (File.Exists(url))return (url); } else {return "~/Images/CompanyProducts/No_image.jpg"; } }   And the html is like this; <asp:Image ID="Image1" ImageUrl='<%# (string) FormatImageUrl( (string) Ev...

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Hi All, I am using Sql server 2005 and VS 2005 C#. Can anybody explain howz solve this prob? Unable to cast object of type 'System.DBNull' to type 'System.String'. 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: Unable to cast object of type 'System.DBNull' to type 'System.String'.Source Error: Line 3496: get { Line 3497: try { Line 3498: ...

Unable to cast object of type 'System.DBNull' to type 'System.String'. #2
 Hi:I am totally new to asp.net and downloaded the club website project. I have not done anything to the events page yet but as soon as i tried to add an event I got the following error. "Unable to cast object of type 'System.DBNull' to type 'System.String'." Can someone help me out here?ThanksBrian  This bug has been covered in the Identified Bugs and fixes section.  http://forums.asp.net/t/970081.aspx There are a few solutions and discussions on fixes, you will need to read through it to find the fix. Support@aspsksolutions.com Without kno...

Unable to cast object of type 'System.DBNull' to type 'System.String'. #2
I am getting this error when I try to run the code below. The error is happening on the last for each loop || foreach (string s in dr.ItemArray) || Please see below:        private void button1_Click(object sender, EventArgs e)        {            string myOutput = "";            DataTable dt = new DataTable();            using (TextReader tr = File.O...

Eventcalender: Unable to cast object of type 'System.DBNull' to type 'System.String'.
 I added an event in the eventcalender. When I try to view the events_calender.aspx I get this error message, what can be wrong??   Server Error in '/bfc_csk' Application. Unable to cast object of type 'System.DBNull' to type 'System.String'. 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: Unable to cast object of type 'System.DBNull' to type 'System.String'.Source Err...

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Byte[]'.
Hi All, I am trying to retrieve a Picture from an SQL 2005 database. Here is my code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ListingID As String = (Request.QueryString("GUID")) 'Connect to the database and bring back the image contents & MIME type for the specified pictureUsing myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionStringListings").ConnectionString) Const SQL As String = "SELECT [Pic1Ext], [Picture1] FROM [Listings] WHERE [ListingID] = @ListingID"C...

"Unable to cast object of type 'System.String' to type 'System.String[]'."
hi i'm using the following statement in my applicationstring[] strTArray = new string[5]; strTArray = (string[])(Session["TextDataArray"]); when i run the application its giving the below error {"Unable to cast object of type 'System.String' to type 'System.String[]'."} can anyone say how to solve this thanks in advance Archu What are you storing in the TextDataArray session? What is the data type you are storing?   RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'.???
Hi everyone, What does this error mean?  ERROR: Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'. Thank's a lot /PepePepe JoseNewbie@C#.Net&jRuby What type is in your DataItem?  A Guid? or a String?  Either way, it's telling you cant cast it to a aspnet_User type.  Let us know what your DataItem is and we can help further.Good Luck and happy programming!Let's build community! If my post helped you, mark it as the Answer and I will do the same when you help me.....

How do I get around this error "Unable to cast object of type 'System.DBNull' to type 'System.String' "
I am using Visual Developer 2008 Express Edition for the first time, and I keep getting the following error below. The site allows anyone to enter with a valid username and password, but even when I logoff the site I get the same error....like the memory or database is not getting refreshed. I would think that when I initially compile the site that anything left in memory would be flushed out. Can someone please help me to figure this out. Thanks,Ramell P.S. The site is programmed using C#    Unable to cast object of type 'System.DBNull' to type 'System.String'. 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: Unable to cast object of type 'System.DBNull' to type 'System.String'.Source Error: Line 57: } Line 58: Line 59: <asp:Label ID="Label2" runat="server" Text='<%# SharedRoutines.truncate((string)Eval("description")) %>' /> Line 60: <a href='<%# "News_View.aspx?Articleid=" + Convert.ToString(Eval("ID")) %>'>read more Line 61: &raquo;</a>Source File: e:\Web Site Portfolio\Greater_Mt_Olive\WebPartControls\RecentNews.ascx    Line: 59 Stack Trace: [InvalidCas...

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
Hi, I have developed a custom server control for .NET Framework 2.0. The server control has a property named BinaryData of type byte[]. I marked this property to be data bindable. Now, I have varbinary(Max) type of field in my SQL Database and I have used SQLDataSource and bound this varbinary(Max) field with the property BinaryData (byte[]) of my control. It is working fine as long as the data value is not NULL. Now, In my control, I have handled the NULL value so that no Exception is thrown. Still, when I bind this property using the SQLDataSource, I get Error "Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'." I am not sure if I can do anything to stop this erro within my control. If it is not possible from the control, then what is the workaround that I can do in my ASPX page in order to stop this error ? Thanks a lot in advance. You are reading in these values from a reader and casting them to their appropriate values. However, since you allow null values in your database table, if there is a null value in your resultant set, it will return DBNull.Value to your reader. This value cannot be casted into a primitive type. Thus you must check for it when you are reading it in and assign it accordingly. For instance,this._strSomeValue = (sdrReader["SomeField"] == DBNull.Value)? "assign default value" : sdrReader["SomeField"].ToString();basically check if it is DBNull.Value when you are reading...

Unable to cast object of type 'System.UInt32' to type 'System.String'?
Hi all,I'm trying to retrieve a column in my table (MySQL), this is the primary key of that table, and here is my code: public string GetAsocPKByUserName(string UserName) { MySqlConnection conn = new MySqlConnection(); MySqlCommand myCommand = new MySqlCommand(); string ASOC_PK = string.Empty; try { conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); myCommand = new MySqlCommand("SELECT Distinct ASOC_PK FROM associates WHERE UserName = '" + UserName + "'"); ASOC_PK = (string)MySqlHelper.ExecuteScalar(conn, myCommand.CommandText); } catch (Exception ex) { throw ex; } finally { conn.Close(); myCommand.Dispose(); } return ASOC_PK; } On my code-behind page, here is what I did:BlogsDS getID = new BlogsDS();Session["ASOC_PK"] = getID.GetAsocPKByUserName(Session["IUser"].ToString()) However, I receive this error each time I run it:Server Error in '/ERC' Application. Unable to cast object of type 'System.UInt32' to type 'System.String'. Description: An unhandled exception occurred during the execution of the current web request. Please review the st...

Unable to cast object of type 'System.Int64' to type 'System.String'
Hi friends I am getting the following error..."Unable to cast object of type 'System.Int64' to type 'System.String'." for the following line of code  if ((QSDealID) == (dr.GetString(1).ToString()))...............need ur help...Gurjeet,England First of all, the ToString of the GetString method is not needed because the GetString will return a string. The prolem with your code is that QSDealID is of type System.Int64, right? So a Int64 can't be compared with a string. The DataReader have a method that can return a Int64, so instead of using GetString(1), use GetInt64. if (QSDealID == dr.GetInt64(1))/Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog is ur QSDealID is interger??? i think if it is then u r required to convert it into string or convert dr.Getstring(0).tostring into Int64Thanks, Mahadeo-----------------------------------------------Best is Not the END point, but a starting point for Innovation------------------------------------------------Remember to mark posts as the "Answer" to help future users....

Unable to cast object of type 'System.DateTime' to type 'System.String'.
 Hi,      I got this field (dateSubmitted) having a data type of DateTime but I receive this error "Unable to cast object of type 'System.DateTime' to type 'System.String'."       All value for dateSubmitted field are 12/27/2007 12:00:00 AM. cheers,imperialx  imperialx:I got this field (dateSubmitted) having a data type of DateTime but I receive this error "Unable to cast object of type 'System.DateTime' to type 'System.String'." Can you explain it further as to, where you're getting this error ?Thanks,Dhimant Trivedi"When the going gets tough, tough gets going.""Mark as Answer" the post(s) which helped you solve the problem  Hi dhimant,                    I have a Gridview and binded to a LinqDatasource, which shows all data field, one field is named dateSubmitted having a data type NCharVar but an error occurs if I set it to DateTime type. cheers,imperialx       imperialx:one field is named dateSubmitted having a data type NCharVar but an error occurs if I set it to DateTime type. AFAIK, the convert between nvarchar and datetime data type is implicit, which means you don't have to explicitly use cast or convert functions to convert a datetime value to nvarchar or vice versa...

Unable to cast object of type 'System.String[]' to type 'System.IConvertible'.
hi expert   i try get the string from request.querystring("CID") from the error messege i know that is string[] (array) how to convert it to int32 and request.querystring("CID") is int value   Line 19: protected void ObjectDataSourceCarPicture_Inserting(object sender, ObjectDataSourceMethodEventArgs e) Line 20: { Line 21: e.InputParameters.Add("CID", Convert.ToInt32(Request.QueryString.GetValues("CID")) ); Line 22: // e.InputParameters.Add("CID", Convert.ToInt32( Convert.ToString( a Request.QueryString.GetValues("CID"))))); Line 23: } i already try search from google but still not get the solution Why dont you carry it out this way: string result = Request.QueryString["CID"]; //Parses the given string, throwing some kind of error when its //not a number int cid = Int32.Parse(result);And then use the cid whereever you want!Hope that helps.So simple... yet so effective.My "Life"ly Blog thanks for reply it works other that i did a mistake Request.QueryString.GetValues("CID")   to Request.QueryString.Get("CID") Watch out for the other thing that I mentioned in my code.. you can use Request.QueryString["CID"] to index into the QueryString collection. Saves some hassle.Smiles.So simple... yet so effective.My "Life"ly Blog...

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
I'm getting Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'. anyone knows how to write some code to check if my binary data is null then continue check another data? I've tried but seems that byte and string can't convert...  (hope someone can provide me code in VB and where to insert them :))  Here's my code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ID As Integer = Convert.ToInt32(Request.QueryString("ID"))Using myConnection As New SqlConnection(Configuratio...

Unable to cast object of type 'System.String' to type 'System.Array'
I really need to get this working! I have dimensioned fnames in line 2 to 200 slots. This code gets all the file names in a subdirectory and places them into an array. First files(), a dynamic array, gets the full path. Then line 9 splits it up into it's parts. I grab the last part (the filename) and store it into fnames. The message is  Unable to cast object of type 'System.String' to type 'System.Array'.  How do I get this to work?  Filenames is an array. Line 9 works. It takes a string (str) and converts it into the Array filenames. Why doesn't the n...

Null values and Profile data "Unable to cast object of type 'System.DBNull' to type 'System.String'"
I've made my own ProfileProvider but when I am trying to read null values by txt.Text = Profile.FirstName I get the error "Unable to cast object of type 'System.DBNull' to type 'System.String'."This is how the code (which I don't write by myself looks like): How to fix the problem??public virtual string FirstName { get { return ((string)(this.GetPropertyValue("FirstName"))); } set { this.SetPropertyValue("FirstName", value); } }  You can check for a null value as sh...

Update error , "Unable to cast object of type 'System.DBNull' to type 'System.String'" , using DataSet as a datasource
Hi All, The following sample code is for testing dw.UpdateData using dataset as the data source. The data retrieval and display part under Form1_Load works fine. However, inputting some values in a new row and calling dw.UpdateData causes the following error: "Unable to cast object of type 'System.DBNull' to type 'System.String'" The error seems to occur when a datawindow column value has been changed from null value. Does anyone know how to fix the error ? Thank you for your advice. I use DW2.5 (build 8542), VS2005 pro, MS SQL Express. ...

Unable to cast object of type 'System.String' to type 'System.Byte[]' error
Hello, I have some binary data in a MySQL database, and im trying to convert it to a file. Before, when i was using the ms sql express 2005 database, everything was working fine. But then i migrated to MySQL because of budget issues. The following is the block of code that produces the error.private void showDbImage() {string ImageId = Request.QueryString["img"];   //build our query statementstring sqlText = "SELECT DownloadFile, DownloadType FROM DownloadTable WHERE DownloadName = '" + ImageId +"'";  OdbcConnection connection = new OdbcConnection( ConfigurationManager.ConnectionStrings["mySqlConnectionString"].ConnectionString ); OdbcCommand command = new OdbcCommand( sqlText, connection ); //open the database and get a datareader connection.Open();OdbcDataReader dr = command.ExecuteReader(); if (dr.Read()) //yup we found our file {Response.ContentType = dr["DownloadType"].ToString();Response.BinaryWrite((byte[])dr["DownloadFile"]); //downloadFile is the column that contains the binary data } connection.Close(); } However, when this code runs, i get the following error in my browser. Unable to cast object of type 'System.String' to type 'System.Byte[]'. The "DownloadFile" column contains the binary data of the file, and its a "LONGTEXT" type. Before, when i was using sql express 2005, the column was defined as an "image" typ...

InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
I get the above error when using the DynamicDataController for a simple schema that looks like the one listed below. It happens when there is actually data in the 2 tables and I try to list the contents of b. I have a sample application that demonstrates this in full if anyone needs it. The work-around is to add a varchar field to table a, and then the exception goes away. I'd rather not do this, so if you know of any code-based workarounds, I'm all ears. The full stack trace is also listed below the schema. If I need to report this to a better place, I'd be happy to do that. CREATE TABLE a (  [id] [int] IDENTITY(1,1) NOT NULL primary key,  [date] [datetime] NULL)CREATE TABLE b (  [id] [int] IDENTITY(1,1) NOT NULL primary key,  [a_id] [int] NULL,  [amount] [decimal](17, 4) NULL)ALTER TABLE [dbo].[b] WITH CHECK ADD CONSTRAINT [FK_b_a] FOREIGN KEY([a_id])REFERENCES [dbo].[a] ([id])GOALTER TABLE [dbo].[b] CHECK CONSTRAINT [FK_b_a]GO   [InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.] System.Web.DynamicData.DynamicMetaTable.GetDisplayString(Object value) +138 ASP.app_shared_dynamicdatafields_foreignkey_ascx.GetDisplayString() in c:\dev\mvc\DynamicDataFKBug\DynamicDataFKBug\App_Shared\DynamicDataFields\ForeignKey.ascx:6 ASP.app_shared_dynamicdatafields_foreignkey_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\dev\mvc\DynamicDataFKB...

ERROR: Unable to cast object of type 'System.Boolean' to type 'System.String'
I created a class to update, insert, select and delete data with an object data source but I am getting the following error... body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-wei...

Web resources about - Unable to cast object of type 'System.DBNull' to type 'System.String' - asp.net.club-site-starter-kit

Resources last updated: 3/9/2016 10:27:16 PM