locked
Mobile Data Binding RRS feed

  • Question

  • User1214340414 posted

    Hi,

    I am a beginner to ASP.NET and I am interested in learning how to data bind the mobile controls to the sqlexpress database.  Most of the resources that I have found online or in books cover a lot of stuff that I don't really need to know and only gloss over mobile controls and data binding.  I'm not interested in creating dynamic site for PCs and normal web browers only sites for cell phones.  If you would be interested in helping out I would gladly pay for your time.  Contact me at salimkadar@yahoo.com.

    Tuesday, June 27, 2006 2:43 PM

All replies

  • User-277473267 posted
    let's say you want to bind data to list control
    you add list control with name LResult to your mobile web form
    in code behind file add

    Imports System.Data
    Imports System.Data.SqlClient


    'on page load add
     Protected Sub Page_Load(ByVal sender As Object, _
           ByVal e As System.EventArgs) Handles Me.Load

            If Not Page.IsPostBack Then
                Dim MyConnection As SqlConnection
                Dim MyCommand As SqlCommand
                Dim MyReader As SqlDataReader

                MyConnection = New SqlConnection()
     'change server with your sqlexpress server name
                MyConnection.ConnectionString = "server=UCO-6084D4AA0DD\SQLEXPRESS;database=Northwind;Trusted_Connection=yes"



                MyCommand = New SqlCommand()
                MyCommand.CommandText = " SELECT TOP 3 * FROM CUSTOMERS "
                MyCommand.CommandType = CommandType.Text
                MyCommand.Connection = MyConnection

                MyCommand.Connection.Open()
                MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)

                LResult.DataSource = MyReader
                LResult.DataBind()

                MyCommand.Dispose()
                MyConnection.Dispose()
            End If

        End Sub

    and that's it it should pull top 3 customers from northwind table and bind it to the list control

    Sunday, July 2, 2006 6:00 PM