Link to home
Start Free TrialLog in
Avatar of p0217859_05
p0217859_05

asked on

DataGrid Problem

Hi all... I've got a problem.. i am trying to do a e-commerce application in Microsoft.NET web matrix program that will retrieve all the orders when i click on the button.
In my design mode, i have a datagrid and a button.
In the code mode, i inserted these codes:
---------------------------------------------------------------
Sub Button1_Click(sender As Object, e As EventArgs)
    Dim wsProxy as new IBuySpy.InstantOrder()

    Dim userName As String
    Dim password As String
    Dim orderID As Integer

    DataGrid.DataSource = wsProxy.CheckStatus(userName,password,orderID)
    DataGrid1.DataBind()
End Sub
----------------------------------------------------------
I think i did not declare the variable correctly. Can anyone help me to correct it? I don't know how to make the page work...
Thanks lots..
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of p0217859_05
p0217859_05

ASKER

i am not sure...
i have this in a file called InstantOrder.asmx


<%@ WebService Language="VB" Class="InstantOrder" %>

Imports System
Imports System.Web.Services
Imports ASPNET.StarterKit.Commerce

Public class InstantOrder : Inherits WebService

    '*******************************************************
    '
    ' InstantOrder.OrderItem() Method
    '
    ' The OrderItem method enables a remote client to programmatically
    ' place an order using a webservice.
    '
    '*******************************************************

    <WebMethod(Description:="The OrderItem method enables a remote client to programmatically place an order using a WebService.", EnableSession:=false)> _
    Public Function OrderItem(ByVal userName As String, ByVal password As String, ByVal productID As Integer, ByVal quantity As Integer) As Integer

        ' Login client using provided username and password
        Dim accountSystem As ASPNET.StarterKit.Commerce.CustomersDB = New ASPNET.StarterKit.Commerce.CustomersDB()
        Dim customerId As String = accountSystem.Login(userName, ASPNET.StarterKit.Commerce.Security.Encrypt(password))

        If customerId Is Nothing Then
            Throw New Exception("Error: Invalid Login!")
        End If

        ' Wrap in try/catch block to catch errors in the event that someone types in
        ' an invalid value for quantity
        Dim qty As Integer = System.Math.Abs(quantity)
        If qty = quantity And qty < 1000 Then

            ' Add Item to Shopping Cart
            Dim myShoppingCart As ASPNET.StarterKit.Commerce.ShoppingCartDB = New ASPNET.StarterKit.Commerce.ShoppingCartDB()
            myShoppingCart.AddItem(customerId, productID, quantity)

            ' Place Order
            Dim orderSystem As ASPNET.StarterKit.Commerce.OrdersDB = New ASPNET.StarterKit.Commerce.OrdersDB()
            Dim orderID As Integer = orderSystem.PlaceOrder(customerId, customerId)

            ' Return OrderDetails
            Return orderID
        Else
            ' invalid input
            Return Nothing
        End If

    End Function

    '*******************************************************
    '
    ' InstantOrder.CheckStatus() Method
    '
    ' The CheckStatus method enables a remote client to programmatically
    ' query the current status of an order in the Commerce System.
    '
    '*******************************************************

    <WebMethod(Description:="The CheckStatus method enables a remote client to programmatically query the current status of an order in the ASPNETCommerce System.", EnableSession:=false)> _
    Public Function CheckStatus(ByVal userName As String, ByVal password As String, ByVal orderID As Integer) As OrderDetails

        ' Login client using provided username and password
        Dim accountSystem As ASPNET.StarterKit.Commerce.CustomersDB = New ASPNET.StarterKit.Commerce.CustomersDB()
        Dim customerId As String = accountSystem.Login(userName, ASPNET.StarterKit.Commerce.Security.Encrypt(password))

        If customerId = "" Then
            Throw New Exception("Error: Invalid Login!")
        End If

        ' Return OrderDetails Status for Specified Order
        Dim orderSystem As ASPNET.StarterKit.Commerce.OrdersDB = New ASPNET.StarterKit.Commerce.OrdersDB()
        Return orderSystem.GetOrderDetails(orderID, customerId)

    End Function

   <WebMethod> Function GetOrders() As System.Data.DataSet
        Dim connectionString As String = "server='(local)'; user id='sa'; password='346Password'; database='Commerce'"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

        Dim queryString As String = "SELECT [CMRC_OrderDetails].[OrderID], [CMRC_OrderDetails].[ProductID], [CMRC_Cust"& _
"omers].[EmailAddress], [CMRC_Customers].[CustomerID], [CMRC_OrderDetails].[UnitC"& _
"ost], [CMRC_OrderDetails].[Quantity], [CMRC_Customers].[FullName], [CMRC_Custome"& _
"rs].[Password] FROM [CMRC_OrderDetails], [CMRC_Customers]"
        Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
        dataAdapter.SelectCommand = dbCommand
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)

        Return dataSet
    End Function
End Class
--------------------------------------------------------------------------------------
and using this, i created another aspx page, and created a proxy linked to the asmx page.
i now want to display username, password and orderID, but i am only able to everything that i extract from the database.
How do i specify the specific things i want to display?
thanks for ur quick response.
the datagrid can display items, but it displays everything i have that i extracted from the database.
this is what i have in the asmx page that i used to generate a proxy with.

<%@ WebService Language="VB" Class="InstantOrder" %>

Imports System
Imports System.Web.Services
Imports ASPNET.StarterKit.Commerce

Public class InstantOrder : Inherits WebService

    '*******************************************************
    '
    ' InstantOrder.OrderItem() Method
    '
    ' The OrderItem method enables a remote client to programmatically
    ' place an order using a webservice.
    '
    '*******************************************************

    <WebMethod(Description:="The OrderItem method enables a remote client to programmatically place an order using a WebService.", EnableSession:=false)> _
    Public Function OrderItem(ByVal userName As String, ByVal password As String, ByVal productID As Integer, ByVal quantity As Integer) As Integer

        ' Login client using provided username and password
        Dim accountSystem As ASPNET.StarterKit.Commerce.CustomersDB = New ASPNET.StarterKit.Commerce.CustomersDB()
        Dim customerId As String = accountSystem.Login(userName, ASPNET.StarterKit.Commerce.Security.Encrypt(password))

        If customerId Is Nothing Then
            Throw New Exception("Error: Invalid Login!")
        End If

        ' Wrap in try/catch block to catch errors in the event that someone types in
        ' an invalid value for quantity
        Dim qty As Integer = System.Math.Abs(quantity)
        If qty = quantity And qty < 1000 Then

            ' Add Item to Shopping Cart
            Dim myShoppingCart As ASPNET.StarterKit.Commerce.ShoppingCartDB = New ASPNET.StarterKit.Commerce.ShoppingCartDB()
            myShoppingCart.AddItem(customerId, productID, quantity)

            ' Place Order
            Dim orderSystem As ASPNET.StarterKit.Commerce.OrdersDB = New ASPNET.StarterKit.Commerce.OrdersDB()
            Dim orderID As Integer = orderSystem.PlaceOrder(customerId, customerId)

            ' Return OrderDetails
            Return orderID
        Else
            ' invalid input
            Return Nothing
        End If

    End Function

    '*******************************************************
    '
    ' InstantOrder.CheckStatus() Method
    '
    ' The CheckStatus method enables a remote client to programmatically
    ' query the current status of an order in the Commerce System.
    '
    '*******************************************************

    <WebMethod(Description:="The CheckStatus method enables a remote client to programmatically query the current status of an order in the ASPNETCommerce System.", EnableSession:=false)> _
    Public Function CheckStatus(ByVal userName As String, ByVal password As String, ByVal orderID As Integer) As OrderDetails

        ' Login client using provided username and password
        Dim accountSystem As ASPNET.StarterKit.Commerce.CustomersDB = New ASPNET.StarterKit.Commerce.CustomersDB()
        Dim customerId As String = accountSystem.Login(userName, ASPNET.StarterKit.Commerce.Security.Encrypt(password))

        If customerId = "" Then
            Throw New Exception("Error: Invalid Login!")
        End If

        ' Return OrderDetails Status for Specified Order
        Dim orderSystem As ASPNET.StarterKit.Commerce.OrdersDB = New ASPNET.StarterKit.Commerce.OrdersDB()
        Return orderSystem.GetOrderDetails(orderID, customerId)

    End Function

   <WebMethod> Function GetOrders() As System.Data.DataSet
        Dim connectionString As String = "server='(local)'; user id='sa'; password='346Password'; database='Commerce'"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

        Dim queryString As String = "SELECT [CMRC_OrderDetails].[OrderID], [CMRC_OrderDetails].[ProductID], [CMRC_Cust"& _
"omers].[EmailAddress], [CMRC_Customers].[CustomerID], [CMRC_OrderDetails].[UnitC"& _
"ost], [CMRC_OrderDetails].[Quantity], [CMRC_Customers].[FullName], [CMRC_Custome"& _
"rs].[Password] FROM [CMRC_OrderDetails], [CMRC_Customers]"
        Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
        dataAdapter.SelectCommand = dbCommand
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)

        Return dataSet
    End Function
End Class
---------------------------------------------------------------------------------------------------------
using this, i managed to display all the items, however, i need to only display the username, password and orderID.
how do i declare the items i want to display?
CheckStatus returns a "getOrderDetails"...which you didn't post...but I'm going to assume it is just like "GetOrders" and returns a dataset...in which case if you wanted to use the same dataset and just pull one value into a textbox or something...you can try...

        Dim ds As DataSet = New DataSet
        ds = wsProxy.CheckStatus(userName,password,orderID)
        Dim strUsername As String = ds.Tables(0).Rows(0)("FullName").ToString()


thanks.. i solved it.. :D sorry took so long...