Mobile sql data connection

Last post 06-26-2009 11:22 AM by ronhawker. 4 replies.

Sort Posts:

  • Mobile sql data connection

    06-23-2009, 12:21 PM
    • Member
      152 point Member
    • ronhawker
    • Member since 09-01-2005, 7:28 PM
    • Posts 147

    How do you go about getting a mobile app to say get a detailsview from a sql database. I am using VS2005 and the mobile web forms available but none there and it says you need to use a template to use the data controls.

    Ronhawker
  • Re: Mobile sql data connection

    06-25-2009, 7:36 AM
    • Member
      332 point Member
    • Bullonprowl
    • Member since 08-16-2005, 10:04 AM
    • Chennai
    • Posts 87

    Hi, Can you please tell in detail wat exactly you are trying to do? You are trying to do with Mobile Web App? Can you share the Code?

    Regs,
    Bharani

    Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
  • Re: Mobile sql data connection

    06-25-2009, 4:22 PM
    • Member
      152 point Member
    • ronhawker
    • Member since 09-01-2005, 7:28 PM
    • Posts 147

     I did get past the data connection by using a sqldatadapter. There seems to be a real lack of microsoft mobile information around. I am now working with the objectlist method and getting it setup properly so it shows results from the query. The code and code behind are below:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultMobile1.aspx.vb" Inherits="_Default" %>

    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <mobile:Form ID="frmMainMenu" Runat="server">
            <mobile:List ID="lstMainMenu" Runat="server">
                <Item Text="By Name" Value="1" />
                <Item Text="By Zip" Value="2" />
                <Item Text="By Brand" Value="3" />
            </mobile:List>
        </mobile:Form>
        <mobile:Form ID="frmSearchName" Runat="server" Title="Enter a Name">
            <mobile:Label ID="lblSearchName" Runat="server">Enter Store Name</mobile:Label>
            <mobile:TextBox ID="txtSearchName" Runat="server">
            </mobile:TextBox>
            <mobile:Command ID="cmdSearchName" Runat="server">Search</mobile:Command>
        </mobile:Form>
        <mobile:Form ID="frmSearchId" Runat="server" Title="Enter an ID">
            <mobile:Label ID="lblSearchId" Runat="server">Enter ZIP</mobile:Label>
            <mobile:TextBox ID="txtSearchId" Runat="server">
            </mobile:TextBox>
            <mobile:Command ID="cmdSearchId" Runat="server">Search</mobile:Command>
        </mobile:Form>
        <mobile:Form ID="frmSearchCategory" Runat="server" Title="Select a Category">
            <mobile:List ID="lstCategories" Runat="server">
            </mobile:List>
        </mobile:Form>
        <mobile:Form ID="frmResult" Runat="server" Title="Search Result">
            <mobile:ObjectList ID="lstResult" Runat="server" CommandStyle-StyleReference="subcommand"
                LabelStyle-StyleReference="title" AutoGenerateFields="False">
                <Field Name="Name" />
            </mobile:ObjectList>
        </mobile:Form>&nbsp;
    </body>
    </html>

    code behind:

    Imports System.Data
    Imports System.Data.SqlClient

    Partial Class _Default
        Inherits System.Web.UI.MobileControls.MobilePage

        Private ds As New DataSet()

        Private Sub Page_Load(ByVal sender As System.Object, _
                 ByVal e As System.EventArgs) _
                 Handles MyBase.Load
            If Not Page.IsPostBack Then
                GetData()
            End If
        End Sub

        Public Sub GetData()
            Dim cn As New SqlConnection("sqlconnection1")
            Dim Sql As String = "select [StoreName],[StoreStreetAddress],[StoreCity],[StoreState],[StoreZip],[StorePhone],[StoreBrands],[StoreHours],[StoreServiceHours] from New_Store"
            Dim da As New SqlDataAdapter(Sql, cn)
            da.Fill(ds, "Store")
        End Sub

        Protected Sub lstMainMenu_ItemCommand(ByVal sender As Object, _
                ByVal e As System.Web.UI.MobileControls.ListCommandEventArgs) _
                Handles lstMainMenu.ItemCommand
            If e.ListItem.Value = 1 Then
                Me.ActiveForm = frmSearchName
            End If
            If e.ListItem.Value = 2 Then
                Me.ActiveForm = frmSearchId
            End If
            If e.ListItem.Value = 3 Then
                GetData()
                Me.ActiveForm = frmSearchCategory
                lstCategories.DataSource = ds.Tables("Store").DefaultView
                lstCategories.DataTextField = "StoreName"
                lstCategories.DataValueField = "StoreAlias"
                lstCategories.DataBind()
            End If
        End Sub

        Public Sub ShowResults()
            lstResult.DataSource = ds.Tables("Store").DefaultView
            lstResult.LabelField = "StoreName"
            lstResult.DataBind()
            Me.ActiveForm = frmResult
        End Sub


        Protected Sub cmdSearchName_Click(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles cmdSearchName.Click
            GetData()
            ds.Tables("Store").DefaultView.RowFilter = _
             String.Format("StoreName like '{0}%'", txtSearchName.Text)
            ShowResults()
        End Sub


        Protected Sub cmdSearchId_Click(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles cmdSearchId.Click
            GetData()
            ds.Tables("Store").DefaultView.RowFilter = _
                String.Format("StoreAlias = {0}", txtSearchId.Text)
            ShowResults()
        End Sub

        Protected Sub lstCategories_ItemCommand(ByVal sender As Object, _
                ByVal e As System.Web.UI.MobileControls.ListCommandEventArgs) _
                Handles lstCategories.ItemCommand
            GetData()
            ds.Tables("Store").DefaultView.RowFilter = _
             String.Format("StoreAlias = {0}", e.ListItem.Value)
            ShowResults()
        End Sub
    End Class

    Ronhawker
  • Re: Mobile sql data connection

    06-26-2009, 5:18 AM
    • Member
      332 point Member
    • Bullonprowl
    • Member since 08-16-2005, 10:04 AM
    • Chennai
    • Posts 87

    Hi, you need any help with this? 

    Regs,
    Bharani

    Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
  • Re: Mobile sql data connection

    06-26-2009, 11:22 AM
    • Member
      152 point Member
    • ronhawker
    • Member since 09-01-2005, 7:28 PM
    • Posts 147

     I certainly do. I seem to be having a problem getting the hang of the objectlist. The data load, selection setup is staright forward asp but for some reason I do not understand the objectlist setup where is converts the data to the display of the results. This code is an adapted version of a course example from the MCTS exam. It used category lookups of products from the Northwind database and I converted it to a store lookup to be able to have a customer lookup store information by store name, zip code or brands carried. Code is not meant to be complete for all those options but I need to get a handle on the objectlist basics. You can see I am basically using a detailslist method of a key dropdown selection to show extended information.

    Thanks

    Ronhawker
Page 1 of 1 (5 items)