Incorrect in passing parameters

J

JenHu

Hi all,
I received an error: System.NullReferenceException: Object reference
not set to an instance of an object at GenerateA(String&
strEmpID, String& strClientAcct, String& strAcctStatus).

When I run the debug, and in the command line I entered ?strEmpID, and
it does passed the correct employee ID.
However, in the first line of the dataset,
EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")

it generates error message "Object reference not set to an instance of
an object" and stacktrace is "at GenerateA(String& strEmpID,
String& strClientAcct, String& strAcctStatus)"
----------------------------------------------------
Main.vb

Main.VB
-----------------
some codes........

Dim strCurEmployId As String
strCurEmployId = dtrSelectTransactions("EmployID")

smCurBatch.WriteLine(GenerateA(strCurEmployId, boxTopCorp.Text,
"Open"))
some codes...............
------------------------------------------------

Public Function GenerateA(ByRef strEmpID As String, ByRef
strClientAcct As String, ByRef strAcctStatus As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet

GPConnection = New
SqlConnection(".............................................")
Dim GPDataAdapter As New SqlDataAdapter("SELECT
LASTNAME,FRSTNAME,MIDLNAME,SOCSCNUM,ADDRESS1,PHONE1,BRTHDATE FROM
UPR00102 where EmployID= " + strEmpID, GPConnection)

Dim EfundAcct As String
Dim LName (30) As Char
Dim FName (30) As Char
Dim MName (30) As Char

GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")
LName = DS.Tables("AcctInfoTble").Rows(1).Item("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(2)("LASTNAME")
MName = DS.Tables("AcctInfoTble").Rows(3)("MASTNAME")

'Position 1 2A A
strResult.Insert(0, "A ")
'Position 3 10A Employee Number
strResult.Insert(9, strEmpID.PadRight(10, " "))
'Position 13 16N Efund acct number
strResult.Insert(12, EfundAcct.PadLeft(16, " "))

GPConnection.Dispose()
Return strResult.ToString
End Function

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
S

Sahil Malik

JenHu,

Look at these lines -
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")

You are filling GPDataset and checking the value of DS.Tables("...") ..

DS has been done a new on it, but it doesn't have any tables or data yet.

Also, another thing I would recommend reading upon is "TableMappings".

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top