Argh..mand, hvorfor skal det være så svært, eksempel fra M$
Jeg kan ikke få det her eksempel til at virke fra MShttp://samples.gotdotnet.com/quickstart/aspplus/doc/servicesanddata.aspx
DataService.asmx virker fint, koden ser sådan her ud:
<%@ WebService Language="VB" Class="DataService" %>
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports Microsoft.Data.Odbc
Public Class DataService : Inherits WebService
<WebMethod()> Public Function GetTitleAuthors() As DataSet
'Dim MyConnection As SqlConnection = New SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes")
Dim objConnection As New OdbcConnection("Driver={mySQL};Server=localhost;Database=aspnet;Uid=xxx;Pwd=xxx;")
'Dim MyCommand1 As SqlDataAdapter = New SqlDataAdapter("select * from Authors", MyConnection)
Dim objDataAdapter As New OdbcDataAdapter("select test, test33, test44 from test", objConnection)
'Dim MyCommand2 As SqlDataAdapter = New SqlDataAdapter("select * from Titles", MyConnection)
Dim DS As New DataSet
'MyCommand1.Fill(DS, "Authors")
objDataAdapter.Fill(DS, "myTable")
'MyCommand2.Fill(DS, "Titles")
Return DS
End Function
<WebMethod()> Public Function PutTitleAuthors(DS As DataSet) As Integer
Return DS.Tables(0).Rows.Count
End Function
End Class
DataServiceClient.aspx virker ikke!, koden ser sådan her ud:
<%@ Page Language="vb" %>
<%@ import Namespace="DataServiceVB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected Sub Page_Load(Src As Object, E As EventArgs)
Dim D As DataServiceVB.DataService = New DataServiceVB.DataService()
Dim MyData As DataSet = D.GetTitleAuthors()
Authors_DataGrid.DataSource=MyData.Tables("Authors").DefaultView
Authors_DataGrid.DataBind()
Message.InnerHtml = "The number of rows is: " & MyData.Tables("Authors").Rows.Count.ToString()
End Sub
Protected Sub Submit_DataSet(Src As Object, E As EventArgs)
Dim D As DataServiceVB.DataService = New DataServiceVB.DataService()
Dim MyData As DataSet = D.GetTitleAuthors()
'Remove three rows from the Authors table
MyData.Tables("Authors").Rows.RemoveAt(0)
MyData.Tables("Authors").Rows.RemoveAt(1)
MyData.Tables("Authors").Rows.RemoveAt(2)
Dim RowCount As Integer = D.PutTitleAuthors(MyData)
Authors_DataGrid.DataSource=MyData.Tables("Authors").DefaultView
Authors_DataGrid.DataBind()
Message.InnerHtml = "The modified number of rows is: " & RowCount.ToString()
End Sub
</script>
<html>
<head>
</head>
<body style="FONT: 10pt verdana">
<h4>Using Data Access with Web Services
</h4>
<form runat="server">
<input type="submit" value="Remove three rows from the DataSet" runat="server" onserverclick="Submit_DataSet" />
<p>
<span id="Message" runat="server">
<p>
<ASP:DataGrid id="Authors_DataGrid" runat="server" EnableViewState="false" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellSpacing="0" CellPadding="3" ShowFooter="false" BorderColor="black" BackColor="#ccccff" Width="700"></ASP:DataGrid>
</p>
</span>
</p>
</form>
</body>
</html>
Jeg får følgendende fejl:
Compiler Error Message: BC30002: Type 'DataServiceVB.DataService' is not defined.
Source Error:
Line 7: Protected Sub Page_Load(Src As Object, E As EventArgs)
Line 8:
Line 9: Dim D As DataServiceVB.DataService = New DataServiceVB.DataService()
Line 10: Dim MyData As DataSet = D.GetTitleAuthors()
Line 11:
Det skyldes vist at den ikke kan finde det namespace, hvorfor kan den ikke det ?
