Hi, I wrote a function that pulls a record, below:
++++++++++++++++++++++++++++++++++++++++
Public Function getServPlanProgActivity( serviceprogramenroll_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 " & _
"serviceactivity_id, activity_id, " & _
"serviceprogramenroll_id, additional_text " & _
"FROM ServicePlanProgramActivity " & _
"WHERE serviceprogramenroll_id = " &
ctype(serviceprogramenroll_id , integer) & "And activity_id =" &
ctype(activity_id , integer), myConn)
Dim myDataSet As New DataSet()
myAdapter.Fill(myDataSet, "ServicePlanProgramEnroll")
' Return datarow
If myDataSet.Tables(0).Rows.Count > 0 Then
Return myDataSet.Tables(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:
dstServPlanProgProgActivity =
myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"),
reader.Item("id"))
If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then
checktextbox.ctcChecked = true
If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then
checktextbox.ctcText =
dstServPlanProgProgActivity("additional_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.NullReferenceException: Object reference not set to an instance of an
object.
Line 190: If Not IsDBNull(dstServPlanProgProgActivity("activity_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 1559
"News" <ge**@mailcity.com> wrote in message
news:JL********************@magma.ca... Hi, I wrote a function that pulls a record, below:
++++++++++++++++++++++++++++++++++++++++ Public Function getServPlanProgActivity( serviceprogramenroll_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 " & _ "serviceactivity_id, activity_id, " & _ "serviceprogramenroll_id, additional_text " & _ "FROM ServicePlanProgramActivity " & _ "WHERE serviceprogramenroll_id = " & ctype(serviceprogramenroll_id , integer) & "And activity_id =" & ctype(activity_id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill(myDataSet, "ServicePlanProgramEnroll")
' Return datarow If myDataSet.Tables(0).Rows.Count > 0 Then Return myDataSet.Tables(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:
dstServPlanProgProgActivity = myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"), reader.Item("id")) If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then checktextbox.ctcChecked = true If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then checktextbox.ctcText = dstServPlanProgProgActivity("additional_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.NullReferenceException: Object reference not set to an instance of
an object. Line 190: If Not IsDBNull(dstServPlanProgProgActivity("activity_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
dstServPlanProgProgActivity =
myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"),
reader.Item("id"))
If Not dstServPlanProgProgActivity Then
If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then
checktextbox.ctcChecked = true
If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then
checktextbox.ctcText =
dstServPlanProgProgActivity("additional_text")
End If
End If
End If
thanks, but this line "If Not dstServPlanProgProgActivity Then" now gives me
this error:
Operator 'Not' is not defined for type 'System.Data.DataRow'.
"marinov" <tr*@me.com> wrote in message
news:eL*************@TK2MSFTNGP12.phx.gbl... "News" <ge**@mailcity.com> wrote in message news:JL********************@magma.ca... Hi, I wrote a function that pulls a record, below:
++++++++++++++++++++++++++++++++++++++++ Public Function getServPlanProgActivity( serviceprogramenroll_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 " & _ "serviceactivity_id, activity_id, " & _ "serviceprogramenroll_id, additional_text " & _ "FROM ServicePlanProgramActivity " & _ "WHERE serviceprogramenroll_id = " & ctype(serviceprogramenroll_id , integer) & "And activity_id =" & ctype(activity_id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill(myDataSet, "ServicePlanProgramEnroll")
' Return datarow If myDataSet.Tables(0).Rows.Count > 0 Then Return myDataSet.Tables(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:
dstServPlanProgProgActivity = myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"), reader.Item("id")) If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then checktextbox.ctcChecked = true If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then checktextbox.ctcText = dstServPlanProgProgActivity("additional_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.NullReferenceException: Object reference not set to an instance
of an object. Line 190: If Not IsDBNull(dstServPlanProgProgActivity("activity_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
dstServPlanProgProgActivity = myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"), reader.Item("id")) If Not dstServPlanProgProgActivity Then If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then checktextbox.ctcChecked = true If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then checktextbox.ctcText = dstServPlanProgProgActivity("additional_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
dstServPlanProgProgActivity =
myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"),
reader.Item("id"))
If Not dstServPlanProgProgActivity = Nothing Then
If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then
checktextbox.ctcChecked = true
If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext")) Then
checktextbox.ctcText =
dstServPlanProgProgActivity("additional_text")
End If
End If
End If
Regards
Martin
"News" <ge**@mailcity.com> wrote in message
news:Xt********************@magma.ca... thanks, but this line "If Not dstServPlanProgProgActivity Then" now gives
me this error: Operator 'Not' is not defined for type 'System.Data.DataRow'.
"marinov" <tr*@me.com> wrote in message news:eL*************@TK2MSFTNGP12.phx.gbl... "News" <ge**@mailcity.com> wrote in message news:JL********************@magma.ca... Hi, I wrote a function that pulls a record, below:
++++++++++++++++++++++++++++++++++++++++ Public Function getServPlanProgActivity( serviceprogramenroll_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 " & _ "serviceactivity_id, activity_id, " & _ "serviceprogramenroll_id, additional_text " & _ "FROM ServicePlanProgramActivity " & _ "WHERE serviceprogramenroll_id = " & ctype(serviceprogramenroll_id , integer) & "And activity_id =" & ctype(activity_id , integer), myConn) Dim myDataSet As New DataSet() myAdapter.Fill(myDataSet, "ServicePlanProgramEnroll")
' Return datarow If myDataSet.Tables(0).Rows.Count > 0 Then Return myDataSet.Tables(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:
dstServPlanProgProgActivity = myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"), reader.Item("id")) If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then checktextbox.ctcChecked = true If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext"))
Then checktextbox.ctcText = dstServPlanProgProgActivity("additional_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.NullReferenceException: Object reference not set to an instance of an object. Line 190: If Not IsDBNull(dstServPlanProgProgActivity("activity_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
dstServPlanProgProgActivity = myServPlanProgProgEnroll.getServPlanProgActivity(v iewstate("speid"), reader.Item("id")) If Not dstServPlanProgProgActivity Then If Not IsDBNull(dstServPlanProgProgActivity("activity_id" )) Then checktextbox.ctcChecked = true If Not IsDBNull(dstServPlanProgProgActivity("additional_t ext"))
Then checktextbox.ctcText = dstServPlanProgProgActivity("additional_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 =...
|
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...
|
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."
...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |