I have created a web service that access a database and retrieves record
then returns them as a dataset. I am having a problem coding a client
application to use the dataset. Here is the relevent code:
Web Service Code:
Public Function Query(ByVal computername As String) As DataSet
Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("inv.mdb")
Dim sqlStr As String
sqlStr = "SELECT * FROM inv WHERE Decal = '" & computername & "';"
Dim myConnection As New OleDbConnection(conStr)
Dim myCommand As New OleDbCommand(sqlStr, myConnection)
myConnection.Open()
Dim myDataAdapter As New OleDbDataAdapter
myDataAdapter.SelectCommand = myCommand
Dim myDataSet As New DataSet
myDataAdapter.Fill(myDataSet)
myConnection.Close()
Return myDataSet
End Function
Client Code:
Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim computername As String
computername = TextBox1.Text
Dim ws As New invweb.Inventory_Database_Query
Dim querydata As DataSet
querydata.Merge(ws.Query(computername))
End Sub
This generates a
System.NullReferenceException
it says:
Object reference not set to an instance of an object.
on
querydata.Merge(ws.Query(computername))
any suggestion on how to get this to work.
Thanks in advance
David York
John Wadie - 14 Sep 2004 13:17 GMT
You should instantiate the dataset before calling the Merge method, replace
this line
Dim querydata As DataSet
With
Dim querydata As New DataSet
Cheers,
John Wadie
Steve Maine - 14 Sep 2004 23:09 GMT
I'm not a VB.NET guy, but it looks like you're only declaring querydata, not instantiating it. Try this at your client:
>Dim querydata As New DataSet
-steve
http://hyperthink.net/blog
> I have created a web service that access a database and retrieves
> record
[quoted text clipped - 38 lines]
>
> David York