473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Cast" error with VB code in .aspx page, with a twist...

Error is thus: "Cast from type 'DBNull' to type 'String' is not valid."
Simple, right? Well, no (or at least not for me).

Here's a function, followed by the calling code below:

Function GetDetails(ByVa l x As String, ByVal y as String)
Dim conn As New SqlConnection
("server=localh ost;uid=blah;pw d=blah;database =test")
Dim strSQL As String
Dim ds As New DataSet()

strSQL = "SELECT firstv.ocean_ca r, firstv.nr,first v.equip "
strSQL &= "FROM firstv INNER JOIN "
strSQL &= "lla ON firstv.doc + firstv.po = lla.doc + lla.po "
strSQL &= "WHERE firstv.doc = " & x & "AND firstv.po = " & y

Dim da As New SqlDataAdapter( strSQL, conn)
da.Fill(ds, "firstv")
Return ds.Tables("firs tv")
End Function

Calling code:

<asp:DataGrid runat=server id=dgDetails
DataSource=<%#
GetDetails(cont ainer.dataitem( "doc"),containe r.dataitem("po" ))%>
AutoGenerateCol umns=false>
<Columns>
<asp:BoundColum n DataField="ocea n_car"
HeaderText="Car rier"></asp:BoundColumn >
<asp:BoundColum n DataField="nr" HeaderText="Boo king"></asp:BoundColumn >
<asp:BoundColum n DataField="Equi p"
HeaderText="Equ ip"></asp:BoundColumn >
</Columns>
</asp:DataGrid>
The error occurs on the very first line of the calling code above.
Naturally, I thought "ah, it must be pulling in nulls from the doc and
po fields in firstv and that must be the cause." So I opened Query
Analyzer and changed all the nulls (in every column) into blanks. Still
got the error so I went back to QA and changed them all to "xyz."
Still, I got the error!! I thought maybe it had to do with the "ByVal"
statement in the function and switched to ByRef... still no go. Anyone
have any tips, please?
Thanks! And yes, I am still am relatively new to .NET. ;)

Nov 21 '05
10 1661
Roy
Thanks for the help you two... I figured it out. I changed the string
parameters to object parameters then changed them back using .ToString
within the function. Sloppy perhaps, but it works. :)

I have encountered something beyond this though and I'd love your
input. Posting it separately, since it is of a different subject matter.

Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1453
by: raca | last post by:
I am trying to create a generic SOA ServiceInvoker that will accept an XML string that will be used to deserialize an object generated by XSDObjectGen. The hierarchy goes like this: Requests...Request (1..n)... Payload (1)... PayloadCollection (1) ... Payload (0...n) I have the knowledge about the root object Responses which I can create directly. However I don't know what is the type for Request and Payload (These will be versioned...
10
2620
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
1
2324
by: Sandeep | last post by:
Hi, I am trying for word 2000 automation with c#. There I want to get all custom document property of the document as follows: Microsoft.Office.Core.DocumentProperties props = (Microsoft.Office.Core.DocumentProperties)aDoc.CustomDocumentProperties; (where aDoc is active Word document). But this gives me an Invalid Cast Exception. I feel like using the correct syntax. Pls help.
0
1588
by: Peter Afonin | last post by:
Hello: When I try to access a SQL server or a network share from an ASP.Net application that I run on my computer, I run into security problems (for instance, I cannot execute DTS package using Trusted connection or get a file information using FileInfo class). This is probably because my application is running under PETER\ASPNET account, where PETER is my computer's name. I can solve this problem by using Impersonation. However, when...
1
2191
by: Shawn Wildermuth | last post by:
I have some simple code that loads a control with LoadControl and casts it to the codebehind object: Control ctrl = LoadControl("~/Controls/BlogEntryViewer.ascx"); BlogEntryViewer entry = (BlogEntryViewer)ctrl; About 80% of the time this fails in the cast. The BlogEntryViewer.ascx file specifies the right file (and it compiles btw): <%@ Control Language="C#" AutoEventWireup="true" CodeFile="BlogEntryViewer.ascx.cs"
4
3839
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is absolutely no added functionality to it.
3
2015
by: hazz | last post by:
I get an InvalidCastException "Cast from string "6<5" to type 'Boolean is not valid. for If (CInt(objBuyInfo.Budget) & " " & arrRuleList(i).operator & " " & CInt(arrRuleList(i).LeadMemberValue)) Then where arrRuleList(i).operator = ">"
17
2516
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
0
9423
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
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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
7409
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
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.