469,081 Members | 1,582 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

DataAdapter.Fill(dataset): Null exception

Hello all,
I'm developing a web application using VB.Net 2003 and Framework 1.1. This
application queries an AS/400 database. I'm using the IBM OleDb provider
that came with IBM Client Access for Windows (V5R3). Everything works fine
on my development PC, but when I move the application to a Windows Server
2003, it crashes when trying to fill a dataset. I've double-checked that the
Win 2k3 server does have Client Access installed, that it has .NET Framework
1.1, and running IIS. The only difference between my development PC and the
2k3 Server is that my PC is running WinXP Pro (thus it runs IIS v.5.1) while
the server is running IIS v.6.0.
Here is my code:

Public Sub LoadDataSet(ByVal source As String, ByVal Collection As String, _
ByVal table As String, ByVal field As String, ByVal
keyValue As String)

'Connection string to as400 database
conStr400 = "Provider=IBMDA400;Data Source=" & source & _
";User ID=myID;Password=myPwd;DEFAULT COLLECTION=" &
Collection
'Create connection object
conn400 = New OleDb.OleDbConnection(conStr400)

'Building SQL select string
Dim selStr As String = "SELECT " & selectedFields & " FROM " & table
& _
" WHERE " & field & " = " & keyValue & " ORDER
BY DSNUMB"

'Create data adapter
da = New OleDb.OleDbDataAdapter(selStr, conn400)

Dim count As Integer = 0

'Open connection to database. The Response.Write statements are for
debugging purpose only

Response.Write("Conn State before open: " & conn400.State & "<br>")
<----- shows "0"

conn400.Open()

Response.Write("Conn State after open: " & conn400.State & "<br>")
<----- shows "1": connected

'Try to load dataset
Try
ds.Clear()

Response.Write("Before Fill: " & ds.Tables.Count & "<br>")
<----- shows "Before Fill: 0" : ds was created, just doesn't have any data,
yet.

count = da.Fill(ds) <---- Null Exception occurs here

Response.Write("After Fill: " & ds.Tables.Count & "<br>Rec count
= " & count) <----- Doesn't show anything

Catch ex As Exception

TextBox2.Text = "Fill Error: " & ex.Message <------ Shows
"Object reference not set to an instance of the object."
Finally
conn400.Close()
Response.Write("Conn State after close: " & conn400.State &
"<br>") <---- Shows "Finally: 0"
End Try
End Sub

At the line of code where that causes exception, the only objects referred
are the Data Adapter "da" and the DataSet "ds".
The dataset "ds" is not the problem because I can count the number of tables
in it before the fill. So the thing that got left is the data adapter.
Why isn't it created/instanitiated?
Please help... I'm stuck with this for the last 3 days I still can't figure
out the cause/solution for it.
Thank you very much.
Stanav.
Nov 19 '05 #1
2 5503
Stanav,

I've had trouble with this also. I've learned to only use datareaders... I
loop through the data returned and create my own dataset when necessary to
have one. I.e. when returning the dataset via a webservice.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Stanav" <st*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I'm developing a web application using VB.Net 2003 and Framework 1.1. This
application queries an AS/400 database. I'm using the IBM OleDb provider
that came with IBM Client Access for Windows (V5R3). Everything works fine
on my development PC, but when I move the application to a Windows Server
2003, it crashes when trying to fill a dataset. I've double-checked that
the Win 2k3 server does have Client Access installed, that it has .NET
Framework 1.1, and running IIS. The only difference between my development
PC and the 2k3 Server is that my PC is running WinXP Pro (thus it runs IIS
v.5.1) while the server is running IIS v.6.0.
Here is my code:

Public Sub LoadDataSet(ByVal source As String, ByVal Collection As String,
_
ByVal table As String, ByVal field As String, ByVal
keyValue As String)

'Connection string to as400 database
conStr400 = "Provider=IBMDA400;Data Source=" & source & _
";User ID=myID;Password=myPwd;DEFAULT COLLECTION=" &
Collection
'Create connection object
conn400 = New OleDb.OleDbConnection(conStr400)

'Building SQL select string
Dim selStr As String = "SELECT " & selectedFields & " FROM " &
table & _
" WHERE " & field & " = " & keyValue & " ORDER
BY DSNUMB"

'Create data adapter
da = New OleDb.OleDbDataAdapter(selStr, conn400)

Dim count As Integer = 0

'Open connection to database. The Response.Write statements are for
debugging purpose only

Response.Write("Conn State before open: " & conn400.State & "<br>")
<----- shows "0"

conn400.Open()

Response.Write("Conn State after open: " & conn400.State & "<br>")
<----- shows "1": connected

'Try to load dataset
Try
ds.Clear()

Response.Write("Before Fill: " & ds.Tables.Count & "<br>")
<----- shows "Before Fill: 0" : ds was created, just doesn't have any
data, yet.

count = da.Fill(ds) <---- Null Exception occurs here

Response.Write("After Fill: " & ds.Tables.Count & "<br>Rec
count = " & count) <----- Doesn't show anything

Catch ex As Exception

TextBox2.Text = "Fill Error: " & ex.Message <------ Shows
"Object reference not set to an instance of the object."
Finally
conn400.Close()
Response.Write("Conn State after close: " & conn400.State &
"<br>") <---- Shows "Finally: 0"
End Try
End Sub

At the line of code where that causes exception, the only objects referred
are the Data Adapter "da" and the DataSet "ds".
The dataset "ds" is not the problem because I can count the number of
tables in it before the fill. So the thing that got left is the data
adapter.
Why isn't it created/instanitiated?
Please help... I'm stuck with this for the last 3 days I still can't
figure out the cause/solution for it.
Thank you very much.
Stanav.

Nov 19 '05 #2
Thank you for the tip, Justin.
I'll try the datareader today and let you know the results.
Stanav.

S. Justin Gengo wrote:
Stanav,

I've had trouble with this also. I've learned to only use datareaders... I
loop through the data returned and create my own dataset when necessary to
have one. I.e. when returning the dataset via a webservice.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Stanav" <st*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I'm developing a web application using VB.Net 2003 and Framework 1.1. This
application queries an AS/400 database. I'm using the IBM OleDb provider
that came with IBM Client Access for Windows (V5R3). Everything works fine
on my development PC, but when I move the application to a Windows Server
2003, it crashes when trying to fill a dataset. I've double-checked that
the Win 2k3 server does have Client Access installed, that it has .NET
Framework 1.1, and running IIS. The only difference between my development
PC and the 2k3 Server is that my PC is running WinXP Pro (thus it runs IIS
v.5.1) while the server is running IIS v.6.0.
Here is my code:

Public Sub LoadDataSet(ByVal source As String, ByVal Collection As String,
_
ByVal table As String, ByVal field As String, ByVal
keyValue As String)

'Connection string to as400 database
conStr400 = "Provider=IBMDA400;Data Source=" & source & _
";User ID=myID;Password=myPwd;DEFAULT COLLECTION=" &
Collection
'Create connection object
conn400 = New OleDb.OleDbConnection(conStr400)

'Building SQL select string
Dim selStr As String = "SELECT " & selectedFields & " FROM " &
table & _
" WHERE " & field & " = " & keyValue & " ORDER
BY DSNUMB"

'Create data adapter
da = New OleDb.OleDbDataAdapter(selStr, conn400)

Dim count As Integer = 0

'Open connection to database. The Response.Write statements are for
debugging purpose only

Response.Write("Conn State before open: " & conn400.State & "<br>")
<----- shows "0"

conn400.Open()

Response.Write("Conn State after open: " & conn400.State & "<br>")
<----- shows "1": connected

'Try to load dataset
Try
ds.Clear()

Response.Write("Before Fill: " & ds.Tables.Count & "<br>")
<----- shows "Before Fill: 0" : ds was created, just doesn't have any
data, yet.

count = da.Fill(ds) <---- Null Exception occurs here

Response.Write("After Fill: " & ds.Tables.Count & "<br>Rec
count = " & count) <----- Doesn't show anything

Catch ex As Exception

TextBox2.Text = "Fill Error: " & ex.Message <------ Shows
"Object reference not set to an instance of the object."
Finally
conn400.Close()
Response.Write("Conn State after close: " & conn400.State &
"<br>") <---- Shows "Finally: 0"
End Try
End Sub

At the line of code where that causes exception, the only objects referred
are the Data Adapter "da" and the DataSet "ds".
The dataset "ds" is not the problem because I can count the number of
tables in it before the fill. So the thing that got left is the data
adapter.
Why isn't it created/instanitiated?
Please help... I'm stuck with this for the last 3 days I still can't
figure out the cause/solution for it.
Thank you very much.
Stanav.


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by IMRAN SAROIA | last post: by
1 post views Thread by PawelR | last post: by
9 posts views Thread by Nikolay Petrov | last post: by
1 post views Thread by Nikolay Petrov | last post: by
6 posts views Thread by Laura K | last post: by
3 posts views Thread by Newbie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.