473,657 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conversion from type 'DBNull' to type 'String' is not valid.

77 New Member
Hi all,
Please help me in this code:

txtLastNameFM.T ext = IIf(dgFamilyMem ber.CurrentRow. Cells(3).Equals (System.DBNull. Value), "", dgFamilyMember. CurrentRow.Cell s(3).Value)

this is an error I get:
Conversion from type 'DBNull' to type 'String' is not valid.

I know the value of the dgFamilyMember. CurrentRow.Cell s(3).Value= null but the first part of the iif returns false! What is wrong here?

I need to check the value of dgFamilyMember. CurrentRow.Cell s(3).Value) to see if it is Null I need to fill txtlastname.tex t by "" otherwise I want to have the dgFamilyMember. CurrentRow.Cell s(3).Value in that textbox.
Please help me.
Aug 8 '08 #1
3 3240
Curtis Rutland
3,256 Recognized Expert Specialist
You can't compare strings to DBNulls like that.
Aug 8 '08 #2
Sep410
77 New Member
I need to check the value of dgFamilyMember. CurrentRow.Cell s(3).Value) to see if it is Null I need to fill txtlastname.tex t by "" otherwise I want to have the dgFamilyMember. CurrentRow.Cell s(3).Value in that textbox.

Please help me.
Aug 8 '08 #3
Sep410
77 New Member
I found it.
I used IsDBNull(expres sion) before assigning to a string.
Aug 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

22
27874
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = (( curRow == System.DBNull.Value ) ? SqlInt32.Null : (int)curRow ); The errors are (in turn):
7
6261
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then Line 176: If rownumber = 3 Then Line 177: thisfield = WhatCol.Value
6
5430
by: tshad | last post by:
The error I am getting is: ******************************************************************* Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid. Source Error: Line 144: firstName.text = ClientReader("firstName") Line 145: lastName.text = ClientReader("lastName")
3
7481
by: Bob Day | last post by:
VS 2003, sql How do you determine the data type of a column if its value is DBNull? 1)Table: Column1 STRING non-nullable 2) Fill to a DataSet via DataAdapter 3) dim Data_Type_Is as object
10
2412
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
2
2420
by: ibiza | last post by:
Hi all, I'm using a business logic layer as described in this source code : http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src&file=GridViewObject_cs\App_Code\AuthorsComponent.cs&lang=C%23+Source It works very well until I encountered a small problem recently. When it is time to bind the data from the db to my class representing an "author" (let's say, for simplicity), what about if my row...
2
7028
by: Chris | last post by:
Hi again, I want to read all the records of a table with 2 fields. The problem is that some records have null value in the second field. This code below works when all records have both fields fiilled, but gives the error: "Conversion from type 'DBNull' to type 'String' is not valid" when not. ..... comd = New System.Data.OleDb.OleDbCommand("select name,lok from pc",
4
6225
by: SAL | last post by:
I'm sorry if this has been answered before but I didn't see it in a quick scan of the list. The following code is causing an error when the field is null: Error text: Conversion from type 'DBNull' to type 'Date' is not valid. <asp:Calendar ID="Calendar2" runat="server" SelectedDate='<%# Bind("DateReceived") %>' VisibleDate='<%# Eval("DateReceived") %>'></asp:Calendar>
4
6280
by: Michel Vanderbeke | last post by:
Hello, When reading data from a SqlClient.SqlDataReader in VB.NET 2005, I want to display fiels that sometimes are empty. sUser = CStr(rdUser("Name") & Space(1) & CStr(rdUser("First_Name") When the First_Name of a user is empty, I get an error telling me type DBNull cannot be converted to String. Is there a way of solving this problem?
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.