Dealing with .NET Enterprise Services: .NET Remoting, Web Services and Service Components - Working with database based Web Services
(Page 6 of 6 )
Even this part is very similar to what I discussed in the previous section. Let's see the code:
<WebMethod()> _
Public Function getInfo(ByVal strSQL As String) As DataSet
Dim cn As New SqlConnection("Data Source=.;Initial
Catalog=Northwind;User ID=sa")
cn.Open()
Dim adp As New SqlDataAdapter(strSQL, cn)
Dim ds As New DataSet
adp.Fill(ds)
adp.Dispose()
cn.Close()
Return ds
End Function
You can observe that it is very similar to a fundamental data access program, but preceded with “<WebMethod()>” at the front.
And to access the above web service, the client could be something like the following:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim srv As New MyService.DBService
Dim ds As DataSet
ds = srv.getInfo(Me.txtSQL.Text)
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataMember = ds.Tables(0).TableName
End Sub
“dataset” and “datatable” work as offline data. The internal architecture of both of them is made up of XML. And thus I can receive a dataset or data table from the web service and assign it as a data source to data grid!
Remarks
All the sample code attached to this article can also be reused in your applications. But please be aware that the proper configuration is necessary before you attach real time applications. You need to thoroughly test the code before you deploy it at the production level.
Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |