Hi, I wrote a function that pulls a record, below:
+++++++++++++++ +++++++++++++++ ++++++++++
Public Function getServPlanProg Activity( serviceprograme nroll_id As Integer,
activity_id As Integer ) As DataRow
' Connect To db
Dim myConn As New SqlConnection(_ DSN)
Dim dtrHasRows As DataRow
Try
Dim myAdapter As New SqlDataAdapter( "Select " & _
"serviceactivit y_id, activity_id, " & _
"serviceprogram enroll_id, additional_text " & _
"FROM ServicePlanProg ramActivity " & _
"WHERE serviceprograme nroll_id = " &
ctype(servicepr ogramenroll_id , integer) & "And activity_id =" &
ctype(activity_ id , integer), myConn)
Dim myDataSet As New DataSet()
myAdapter.Fill( myDataSet, "ServicePlanPro gramEnroll")
' Return datarow
If myDataSet.Table s(0).Rows.Count > 0 Then
Return myDataSet.Table s(0).Rows(0)
Else
dtrHasRows = Nothing
Return dtrHasRows
End If
Catch ex As Exception
Throw ex
Finally
myConn.Close()
End Try
End Function
+++++++++++++++ +++++++++++++++ +++++++++
This is a snippet where I reference it:
dstServPlanProg ProgActivity =
myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"),
reader.Item("id "))
If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
checktextbox.ct cChecked = true
If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then
checktextbox.ct cText =
dstServPlanProg ProgActivity("a dditional_text" )
End If
End If
+++++++++++++++ +++++++++++++++ +++++++++
Problem is when there is a record it works fine, but if no record found I
get this error:
System.NullRefe renceException: Object reference not set to an instance of an
object.
Line 190: If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
I understand that there is no record for this search criteria, how do I
validate that this function returned Nothing or may be there is a better
way, say assign something to a return value of the function? If I were to
assign some value, how do I assign something to a data type of DataRow?
Thanks,
Gene 3 1570
"News" <ge**@mailcity. com> wrote in message
news:JL******** ************@ma gma.ca... Hi, I wrote a function that pulls a record, below:
+++++++++++++++ +++++++++++++++ ++++++++++ Public Function getServPlanProg Activity( serviceprograme nroll_id As
Integer, activity_id As Integer ) As DataRow ' Connect To db Dim myConn As New SqlConnection(_ DSN) Dim dtrHasRows As DataRow
Try Dim myAdapter As New SqlDataAdapter( "Select " & _ "serviceactivit y_id, activity_id, " & _ "serviceprogram enroll_id, additional_text " & _ "FROM ServicePlanProg ramActivity " & _ "WHERE serviceprograme nroll_id = " & ctype(servicepr ogramenroll_id , integer) & "And activity_id =" & ctype(activity_ id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill( myDataSet, "ServicePlanPro gramEnroll")
' Return datarow If myDataSet.Table s(0).Rows.Count > 0 Then Return myDataSet.Table s(0).Rows(0) Else dtrHasRows = Nothing Return dtrHasRows End If
Catch ex As Exception Throw ex Finally myConn.Close() End Try End Function
+++++++++++++++ +++++++++++++++ +++++++++
This is a snippet where I reference it:
dstServPlanProg ProgActivity = myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"), reader.Item("id ")) If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then checktextbox.ct cChecked = true If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then checktextbox.ct cText = dstServPlanProg ProgActivity("a dditional_text" ) End If End If
+++++++++++++++ +++++++++++++++ +++++++++
Problem is when there is a record it works fine, but if no record found I get this error: System.NullRefe renceException: Object reference not set to an instance of
an object. Line 190: If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id"))
Then
I understand that there is no record for this search criteria, how do I validate that this function returned Nothing or may be there is a better way, say assign something to a return value of the function? If I were to assign some value, how do I assign something to a data type of DataRow?
Thanks,
Gene
to avoid the error you can do this
dstServPlanProg ProgActivity =
myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"),
reader.Item("id "))
If Not dstServPlanProg ProgActivity Then
If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
checktextbox.ct cChecked = true
If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then
checktextbox.ct cText =
dstServPlanProg ProgActivity("a dditional_text" )
End If
End If
End If
thanks, but this line "If Not dstServPlanProg ProgActivity Then" now gives me
this error:
Operator 'Not' is not defined for type 'System.Data.Da taRow'.
"marinov" <tr*@me.com> wrote in message
news:eL******** *****@TK2MSFTNG P12.phx.gbl... "News" <ge**@mailcity. com> wrote in message news:JL******** ************@ma gma.ca... Hi, I wrote a function that pulls a record, below:
+++++++++++++++ +++++++++++++++ ++++++++++ Public Function getServPlanProg Activity( serviceprograme nroll_id As Integer, activity_id As Integer ) As DataRow ' Connect To db Dim myConn As New SqlConnection(_ DSN) Dim dtrHasRows As DataRow
Try Dim myAdapter As New SqlDataAdapter( "Select " & _ "serviceactivit y_id, activity_id, " & _ "serviceprogram enroll_id, additional_text " & _ "FROM ServicePlanProg ramActivity " & _ "WHERE serviceprograme nroll_id = " & ctype(servicepr ogramenroll_id , integer) & "And activity_id =" & ctype(activity_ id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill( myDataSet, "ServicePlanPro gramEnroll")
' Return datarow If myDataSet.Table s(0).Rows.Count > 0 Then Return myDataSet.Table s(0).Rows(0) Else dtrHasRows = Nothing Return dtrHasRows End If
Catch ex As Exception Throw ex Finally myConn.Close() End Try End Function
+++++++++++++++ +++++++++++++++ +++++++++
This is a snippet where I reference it:
dstServPlanProg ProgActivity = myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"), reader.Item("id ")) If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then checktextbox.ct cChecked = true If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then checktextbox.ct cText = dstServPlanProg ProgActivity("a dditional_text" ) End If End If
+++++++++++++++ +++++++++++++++ +++++++++
Problem is when there is a record it works fine, but if no record found
I get this error: System.NullRefe renceException: Object reference not set to an instance
of an object. Line 190: If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
I understand that there is no record for this search criteria, how do I validate that this function returned Nothing or may be there is a better way, say assign something to a return value of the function? If I were
to assign some value, how do I assign something to a data type of DataRow?
Thanks,
Gene
to avoid the error you can do this
dstServPlanProg ProgActivity = myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"), reader.Item("id ")) If Not dstServPlanProg ProgActivity Then If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then checktextbox.ct cChecked = true If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then checktextbox.ct cText = dstServPlanProg ProgActivity("a dditional_text" ) End If End If End If
I'm really sorry
Because i didn't test the code but write directly in the reply i forgot to
put the = Nothing
so the code should be
dstServPlanProg ProgActivity =
myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"),
reader.Item("id "))
If Not dstServPlanProg ProgActivity = Nothing Then
If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
checktextbox.ct cChecked = true
If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text")) Then
checktextbox.ct cText =
dstServPlanProg ProgActivity("a dditional_text" )
End If
End If
End If
Regards
Martin
"News" <ge**@mailcity. com> wrote in message
news:Xt******** ************@ma gma.ca... thanks, but this line "If Not dstServPlanProg ProgActivity Then" now gives
me this error: Operator 'Not' is not defined for type 'System.Data.Da taRow'.
"marinov" <tr*@me.com> wrote in message news:eL******** *****@TK2MSFTNG P12.phx.gbl... "News" <ge**@mailcity. com> wrote in message news:JL******** ************@ma gma.ca... Hi, I wrote a function that pulls a record, below:
+++++++++++++++ +++++++++++++++ ++++++++++ Public Function getServPlanProg Activity( serviceprograme nroll_id As Integer, activity_id As Integer ) As DataRow ' Connect To db Dim myConn As New SqlConnection(_ DSN) Dim dtrHasRows As DataRow
Try Dim myAdapter As New SqlDataAdapter( "Select " & _ "serviceactivit y_id, activity_id, " & _ "serviceprogram enroll_id, additional_text " & _ "FROM ServicePlanProg ramActivity " & _ "WHERE serviceprograme nroll_id = " & ctype(servicepr ogramenroll_id , integer) & "And activity_id =" & ctype(activity_ id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill( myDataSet, "ServicePlanPro gramEnroll")
' Return datarow If myDataSet.Table s(0).Rows.Count > 0 Then Return myDataSet.Table s(0).Rows(0) Else dtrHasRows = Nothing Return dtrHasRows End If
Catch ex As Exception Throw ex Finally myConn.Close() End Try End Function
+++++++++++++++ +++++++++++++++ +++++++++
This is a snippet where I reference it:
dstServPlanProg ProgActivity = myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"), reader.Item("id ")) If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then checktextbox.ct cChecked = true If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text"))
Then checktextbox.ct cText = dstServPlanProg ProgActivity("a dditional_text" ) End If End If
+++++++++++++++ +++++++++++++++ +++++++++
Problem is when there is a record it works fine, but if no record
found I get this error: System.NullRefe renceException: Object reference not set to an instance of an object. Line 190: If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then
I understand that there is no record for this search criteria, how do
I validate that this function returned Nothing or may be there is a
better way, say assign something to a return value of the function? If I were to assign some value, how do I assign something to a data type of
DataRow?
Thanks,
Gene
to avoid the error you can do this
dstServPlanProg ProgActivity = myServPlanProgP rogEnroll.getSe rvPlanProgActiv ity(viewstate(" speid"), reader.Item("id ")) If Not dstServPlanProg ProgActivity Then If Not IsDBNull(dstSer vPlanProgProgAc tivity("activit y_id")) Then checktextbox.ct cChecked = true If Not IsDBNull(dstSer vPlanProgProgAc tivity("additio nal_text"))
Then checktextbox.ct cText = dstServPlanProg ProgActivity("a dditional_text" ) End If End If End If
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: A |
last post by:
Hi Group,
I am trying to find how to insert a blank combo box option in my list of
available choices thus representing no choice. I have a total hack right
now below
DataTable dt = Facility.GetDataTable;
|
by: john |
last post by:
Hi,All MS Tech Gurus:
I need your help!!! It is the second time I post this message, I need get
some feedback ASAP, Please Help!!
Thanks a lot in advance.
John
I have a csharp method, using emit to dynamically generate classes & method
depends on the meta table in the database,here is my situation
1) In One method I generated the code Dynamic IL Code (Depends on the data
pass to it), The generated code works for one dataset but does...
|
by: Justin |
last post by:
I am trying to do a simple update of a single row with the dataset below but
I keep getting this error:
"System.NullReferenceException: Object reference not set to an instance of
an object."
Here is the code:
Me.sqlDataAdapter1.Fill(DataSet1, "Queue")
|
by: carballosa |
last post by:
Hi guys,
I need to use a one row datagrid in my asp.net 1.1 application. The data
source will contain 1 or 0 entries. When no rows of data are present I want
to show an empty row in the datagrid (ie. with empty cells). Unfortunatly I
get no datagrid shown instead. Any idea how I can force the datagrid to show
with an empty row?
Best regards,
|
by: ricolee99 |
last post by:
Hi everyone,
I have a problem that i have been trying to solve for awhile. I'm
given a code where the purpose is to create a general dataset mapper.
Given any dataset, i have a class, "Mapper.cs" that's supposed to map
objects from any type of dataset to any type of object.
Inside Mapper.cs, there's a method,
object Map(Type typeOfObjectToMap, DataSet theDataSet)
| |
by: Familjen Karlsson |
last post by:
Hi
I have downloaded some code and tried it and nothing happens with the
datagrid. Explain what is wrong and what I have to do please. I have tried
to Import the namespace Hamster and it didn't work. Explain what I have to
do to make that work.
Fia
Imports System
Imports System.Windows.Forms
|
by: mcbobin |
last post by:
Hi,
Here's hoping someone can help...
I'm using a stored procedure to return a single row of data ie a
DataRow
e.g.
public static DataRow GetManualDailySplits(string prmLocationID, string
|
by: =?Utf-8?B?cm9kY2hhcg==?= |
last post by:
hey all,
i'm inside a RowDataBound event and i'd like to dynamically add a button to
an empty gridView column with a click event handler. i'm having trouble with
wiring my procedure to the btn click event.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
|
by: champ1979 |
last post by:
I wrote an algorithm to get all the relatives of a person in a family tree. I'm basically getting all the users from the DB and am doing the recursive logic in code, so that there is only 1 call made to the DB. However, I am trying to do the same thing within a stored procedure in SQL using recursive CTEs (I think the performance might be better) but I'm finding it really tough to craft the CTE. I would really appreciate if someone could...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |