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.


 Public Class Form1
    Dim StaffEntryDataSet1 As New StaffEntryDataSet
    Dim SQLConn As New System.Data.SqlClient.SqlConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load

        SQLConn.ConnectionString = "Data Source=XXXX\SQLEXPRESS;Initial 
Catalog=YYY;Integrated Security=True"
        Dim StaffTableAdapter1 As New 
StaffEntryDataSetTableAdapters.StaffTableAdapter
        StaffTableAdapter1.Connection = SQLConn
        '
        ' Retrieve  staff rows, storing into StaffEntryDataSet1.
        '
         StaffTableAdapter1.Fill(StaffEntryDataSet1.Staff)

        dwcStaff.Retrieve(StaffEntryDataSet1.Staff)
    End Sub

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnInsert.Click
        dwcStaff.InsertRow(0)
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnSave.Click
        Try
            dwcStaff.UpdateData()

        Catch ex As Exception
            Dim sErr As String = ""
            sErr = ex.tostring
        End Try
    End Sub
End Class 


0
Takashi
1/29/2009 12:28:32 AM
sybase.datawindow.net 2302 articles. 0 followers. Follow

0 Replies
1180 Views

Similar Articles

[PageSpeed] 13

Reply:

Similar Artilces:

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&...

"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...

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...

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 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'
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:Hyper...

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 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 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.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 O...

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...

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...

Web resources about - Update error , "Unable to cast object of type 'System.DBNull' to type 'System.String'" , using DataSet as a datasource - sybase.datawindow.net

Resources last updated: 1/19/2016 3:10:25 PM