K
kai
Hi, All
I have following Webservice code rom a book, it works well, it returns a
dataset contains customerOrderHis base on CustomerID. But I cannot display
the returning dataset in datagrid.
<WebMethod(Description:="Get an instance of the custom class " & _
"CustomerAndOrderHistoryInfo, which has a field containing a typed " & _
"DataSet of products that the customer has ordered and a field " & _
"for the company name.")> _
Public Function GetCustomerOrderHistory(ByVal custID As String) _
As CustomerAndOrderHistoryInfo
Dim IsConnecting As Boolean = True
While IsConnecting
Dim scnnNW As New SqlConnection(conn)
Dim scmd As New SqlCommand("CustOrderHist", scnnNW)
Dim cohi As New CustomerAndOrderHistoryInfo()
Try
scmd.CommandType = CommandType.StoredProcedure
scmd.Parameters.Add(New SqlParameter("@CustomerID", _
SqlDbType.NChar, 5)).Value = custID
Dim sda As New SqlDataAdapter(scmd)
Dim dsOrderHistory As New dsCustOrderHist()
sda.Fill(dsOrderHistory.CustOrderHist)
..
IsConnecting = False
cohi.Orders = dsOrderHistory
scmd.CommandText = _
"SELECT CompanyName " & _
"FROM Customers " & _
"WHERE CustomerID = @CustomerID"
scmd.CommandType = CommandType.Text
scnnNW.Open()
Dim objReturnVal As Object = scmd.ExecuteScalar()
If Not IsDBNull(objReturnVal) Then
cohi.CompanyName = objReturnVal.ToString
End If
Catch exSql As SqlException
Throw New Exception(exSql.Message)
Catch ex As Exception
If conn = SQL_CONNECTION_STRING Then
conn = MSDE_CONNECTION_STRING
Else
Throw New Exception(ex.Message)
End If
Finally
scnnNW.Close()
End Try
Return cohi
End While
End Function
I use the following code to consume:
Private Sub btnRetrive_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRetrive.Click
Dim ds As DataSet
Dim ds1 As DataSet
Dim CustomerID As String
Dim svc As New Expensive.Main
ds = svc.GetCustomerOrderHistory("ALFKI")
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub
What is my problem?
Thanks
kai
I have following Webservice code rom a book, it works well, it returns a
dataset contains customerOrderHis base on CustomerID. But I cannot display
the returning dataset in datagrid.
<WebMethod(Description:="Get an instance of the custom class " & _
"CustomerAndOrderHistoryInfo, which has a field containing a typed " & _
"DataSet of products that the customer has ordered and a field " & _
"for the company name.")> _
Public Function GetCustomerOrderHistory(ByVal custID As String) _
As CustomerAndOrderHistoryInfo
Dim IsConnecting As Boolean = True
While IsConnecting
Dim scnnNW As New SqlConnection(conn)
Dim scmd As New SqlCommand("CustOrderHist", scnnNW)
Dim cohi As New CustomerAndOrderHistoryInfo()
Try
scmd.CommandType = CommandType.StoredProcedure
scmd.Parameters.Add(New SqlParameter("@CustomerID", _
SqlDbType.NChar, 5)).Value = custID
Dim sda As New SqlDataAdapter(scmd)
Dim dsOrderHistory As New dsCustOrderHist()
sda.Fill(dsOrderHistory.CustOrderHist)
..
IsConnecting = False
cohi.Orders = dsOrderHistory
scmd.CommandText = _
"SELECT CompanyName " & _
"FROM Customers " & _
"WHERE CustomerID = @CustomerID"
scmd.CommandType = CommandType.Text
scnnNW.Open()
Dim objReturnVal As Object = scmd.ExecuteScalar()
If Not IsDBNull(objReturnVal) Then
cohi.CompanyName = objReturnVal.ToString
End If
Catch exSql As SqlException
Throw New Exception(exSql.Message)
Catch ex As Exception
If conn = SQL_CONNECTION_STRING Then
conn = MSDE_CONNECTION_STRING
Else
Throw New Exception(ex.Message)
End If
Finally
scnnNW.Close()
End Try
Return cohi
End While
End Function
I use the following code to consume:
Private Sub btnRetrive_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRetrive.Click
Dim ds As DataSet
Dim ds1 As DataSet
Dim CustomerID As String
Dim svc As New Expensive.Main
ds = svc.GetCustomerOrderHistory("ALFKI")
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub
What is my problem?
Thanks
kai