Hello
I'm trying to make a web service to forward SQL queries from a VB.net plugin to my SQL server and return the result, but have little idea of how to attack this. Have been searching the web and have made something that look like it can work as a web service:
The simple WebService.asmx file:
<%@ WebService Language="VB" Class="MoodAndStyle" %>
Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class MoodAndStyle
Private Function GetDataSet(SQLQuery as String) as DataSet
'1. Create a connection
Dim SQLconn as New SqlConnection("Data Source=10.0.0.5;Initial Catalog=Mood;User Id=moodDBUser;Password=test;")
'2. Create the command object, passing in the SQL string
Dim command as New SqlCommand(SQLQuery, SQLconn)
SQLconn.Open()
'3. Create the DataAdapter
Dim dataAdapter as New SqlDataAdapter()
dataAdapter.SelectCommand = command
'4. Populate the DataSet and close the connection
Dim myDataSet as New DataSet()
dataAdapter.Fill(myDataSet)
SQLconn.Close()
'Return the DataSet
Return myDataSet
End Function
<WebMethod()> Public Function GetArtists() as DataSet
Return GetDataSet("SELECT * FROM Artist")
End Function
End Class
Anyone know what code I need in my VB.net pluging? For starters I would just want a button to get the dataSet.
I have also read about a web service proxy, but if this get's any more complicated than it have to be, I think I'll give up.
Any suggestions would be great!
- Carl