Search

Mobile Stock Quote Tracker

0 views

Getting Started with the Mobile Stock Quote Tracker

Imagine standing at a market stall, surrounded by dozens of trading options, and needing a quick way to check the latest price of a handful of stocks on your phone. That’s the problem this small mobile web app solves. It lets a user pick the symbols they care about, pulls up-to‑date prices from an online source, and displays everything in a format that’s easy to read on a small screen. If you’re comfortable with ASP.NET and basic database concepts, you’ll find the code fairly straightforward.

At its core, the tracker relies on three simple components. First, a list of symbols that the user wants to monitor. Second, a way to pull the current price for each symbol from the internet. And third, a threshold system that can alert the user when a stock moves above a set high value or below a set low value. The user interface is minimal: a menu on the home page, a list of quotes, a list of alerts, and a form for adding new symbols. Behind the scenes, everything is stored in a tiny Microsoft Access database that contains a single table named tblStk

The database structure is deliberately simple so that you can see exactly how each field is used. It contains four columns: StkSymbol stores the ticker symbol; StkHigh holds the user‑defined high threshold; StkLow holds the low threshold; and StkPrice is a transient column added at runtime to hold the current price. The data types are all familiar: Text for the symbol and Number (decimal) for the thresholds.

Prompt
Field Name | Description | Data Type</p> <p>StkSymbol | Stock Symbol | Text</p> <p>StkHigh | High Threshold for alerts | Number (decimal)</p> <p>StkLow | Low Threshold for alerts | Number (decimal)</p>

Why choose Access over something more modern? For a prototype or a lightweight project, Access is quick to set up, requires no server, and works well with ASP.NET’s built‑in data‑access classes. Once you’re comfortable with the idea, you could swap it for SQL Server or even a cloud database without much effort.

To start building the app, open your favorite HTML editor and create a new file called mobstk.aspx. The rest of the article walks you through each logical step: from the first page you see to the moment you add a new ticker. You can either download the complete code sample and run it through once to see the end result, or follow the steps here to write the code yourself. Either way, the goal is to end up with a fully functional mobile‑friendly stock tracker.

Because the app is written as a mobile Web Forms application, you’ll encounter controls like ObjectList and List that render differently on mobile browsers. These controls provide a clean, touch‑friendly layout, which is why the original author chose them over more complex JavaScript frameworks. The code snippets in this article are small but complete enough that you can copy, paste, and run them immediately. In the next section we’ll dive into the home page that brings everything together.

Designing a Simple Yet Effective Home Page

The home page is the entry point for the entire application. Its only job is to give the user three clear options: view quotes, view alerts, or add a new stock. Because the application is meant for mobile devices, the layout must be compact and responsive. The chosen design uses a List control, which turns into a touch‑friendly list of buttons when rendered on a smartphone or tablet. The code that builds this interface is short but powerful.

Here’s a quick look at the markup for the home page. Notice that the List control is bound to an array of strings that represent the menu items. By using a server‑side control, the app automatically adapts to the device’s screen size and input method.

Home Page UI' /></p>
<p>When a user taps one of the items, a server event fires that redirects to the appropriate page. For instance, tapping “View Stock Quotes” loads <code>ViewStkQuotes.aspx</code>, while “View Stock Alerts” loads <code>ViewStkAlerts.aspx</code>. This straightforward routing keeps the codebase clean and reduces the risk of navigation errors.</p>
<p>Although the home page looks simple, the logic that drives it is critical. The <code>List</code> control’s <code>SelectedIndexChanged</code> event captures which item the user chose. From there, a small switch statement determines the destination. The event handler lives in the code‑behind file and looks something like this:</p>
<div class=
Prompt
Protected Sub List1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)</p> <p> Dim selected As String = List1.SelectedValue</p> <p> If selected = "View Stock Quotes" Then</p> <p> Response.Redirect("ViewStkQuotes.aspx")</p> <p> ElseIf selected = "View Stock Alerts" Then</p> <p> Response.Redirect("ViewStkAlerts.aspx")</p> <p> ElseIf selected = "Add Stocks" Then</p> <p> Response.Redirect("AddStock.aspx")</p> <p> End If</p> <p>End Sub</p>

This approach gives the user a single point of entry and a consistent experience across all pages. Because the application is built on ASP.NET Mobile Forms, you don’t need to worry about creating separate mobile templates or writing custom CSS for each view. The framework does the heavy lifting, letting you focus on the core business logic.

In the next section we’ll explore the “View Stock Quotes” page, where the real magic happens: pulling live prices from the web and displaying them in a table. The code that follows is the heart of the tracker, so pay close attention to how the data is fetched and bound to the UI.

Fetching Real‑Time Stock Quotes

Once the user lands on the “View Stock Quotes” page, the app needs to do a few things. First, it must retrieve the list of symbols the user wants to track. Second, for each symbol it must fetch the current price from an external source. Third, it needs to present that information in a way that’s readable on a phone screen.

The data retrieval is handled by a method called FillStocks. The method starts by querying the Access database for all rows in tblStk. The result is stored in a DataSet object, which the code then extends by adding a new column called StkPrice. That column doesn’t exist in the database; it’s created at runtime to hold the price that will be fetched from the internet.

For each row in the DataSet, the code constructs a URL that points to a free online quote service. It then makes an HTTP request, parses the returned HTML or JSON, and extracts the price value. That price is assigned to the StkPrice column of the current row. After the loop completes, the ObjectList control is bound to the DataSet and rendered to the user.

Prompt
Protected Sub FillStocks()</p> <p> Dim sql As String = "SELECT * FROM tblStk"</p> <p> Dim dt As New DataTable</p> <p> Dim da As New OleDbDataAdapter(sql, con)</p> <p> da.Fill(dt)</p> <p> dt.Columns.Add("StkPrice", GetType(Decimal))</p> <p> For Each row As DataRow In dt.Rows</p> <p> Dim price As Decimal = GetQuote(row("StkSymbol").ToString())</p> <p> row("StkPrice") = price</p> <p> Next</p> <p> ObjectList1.DataSource = dt</p> <p> ObjectList1.DataBind()</p> <p>End Sub</p>

The GetQuote helper function encapsulates the network logic. In this example it might use WebClient to download a page and then use string manipulation to pull out the price. Because this part of the code can fail - if the network is down or the quote service changes its format - the real application should wrap the call in a Try…Catch block. The sample deliberately leaves out exception handling to keep the example focused, but in production you would want to log errors and perhaps display a friendly message to the user.

Once the data is bound, the ObjectList control takes over rendering. It’s a mobile‑specific control that automatically formats a table with alternating row colors, touch‑friendly row selection, and a clean look. On a desktop browser, the same markup would still work but might appear as a plain table. That dual‑compatibility is one of the strengths of ASP.NET Mobile Forms.

Below is a screenshot of the populated list of quotes. Notice how each row shows the symbol and its current price, and you can tap a row to drill down into more detail if desired.

Quotes Table' /></p>
<p>With the quotes page finished, the next logical step is to provide alerts. The same <code>FillStocks</code> logic can be adapted to filter symbols that cross the user‑defined thresholds. The “View Stock Alerts” page implements this logic, and the code snippet that follows shows the key difference: a <code>WHERE</code> clause that checks the price against the thresholds.</p>
<p>The alert system doesn’t rely on scheduled tasks or background jobs. Instead, it runs each time the user opens the alerts page. That approach keeps the code simple and eliminates the need for a service that polls the stock market continuously. The downside is that alerts will only trigger when the user actively views the page. If you need real‑time notifications, you’d need to integrate a background worker or push‑notification service. However, for a lightweight prototype, on‑demand alerts are perfectly adequate.</p><h2>Setting and Managing Alerts</h2>
<p>Alerts are the part of the application that turns passive price data into actionable information. When a stock’s price moves beyond a threshold, the user wants to know immediately. The “View Stock Alerts” page builds on the same data‑fetching logic but adds a simple filter to show only those stocks that have crossed the user’s high or low limits.</p>
<p>The filter is applied after the price data has been retrieved. For each row in the dataset, the code checks whether the current price is greater than <code>StkHigh</code> or less than <code>StkLow</code>. If the condition is true, the row is kept; otherwise it’s removed from the dataset before binding to the UI. This ensures that only relevant alerts appear.</p>
<div class=
Prompt
Protected Sub FillAlerts()</p> <p> da.Fill(dt)</p> <p> Dim rowsToRemove As New List(Of DataRow)</p> <p> If price = Convert.ToDecimal(row("StkHigh")) Then</p> <p> ' keep the row</p> <p> Else</p> <p> rowsToRemove.Add(row)</p> <p> End If</p> <p> Next</p> <p> For Each r As DataRow In rowsToRemove</p> <p> dt.Rows.Remove(r)</p> <p> Next</p> <p>End Sub</p>

When a user taps on an alert row, a second page displays detailed information: the symbol, the current price, and the high/low thresholds set by the user. The UI is minimal but informative. If a user sees that a stock has fallen below the low threshold, they might decide to buy; if a stock has climbed above the high threshold, they might consider selling. The simple design keeps the focus on the essential data.

Below is a screenshot of the alerts page, showing a list of stocks that have triggered an alert. The interface is consistent with the rest of the app, using the same ObjectList control for a uniform look.

Alerts Page' /></p>
<p>Because the alerts logic is built on the same data source and functions, it’s easy to maintain. If you later decide to add more sophisticated alert conditions - such as percentage changes, moving averages, or news triggers - you can extend the <code>FillAlerts</code> method without touching the rest of the application.</p>
<p>One important note is that this example does not include user authentication. In a real deployment, you’d want to restrict access so that each user only sees their own symbols and thresholds. That could be done by adding a user identifier to the <code>tblStk</code> table and filtering queries accordingly.</p>
<p>In the next section we’ll explore how a user adds a new stock to the list, setting their own thresholds right from the add‑stock form.</p><h2>Adding New Stocks to the Tracker</h2>
<p>The “Add New Stock” page is where users can extend their watchlist. The form includes three fields: the ticker symbol, a high threshold, and a low threshold. The user enters a symbol like “AAPL”, sets a high threshold like 150, and a low threshold like 120. When they click “Save”, the application inserts a new row into the <code>tblStk</code> table and displays a confirmation message.</p>
<p>Below is the markup for the add‑stock form. It uses a simple <code>TextBox</code> control for each input and a <code>Button</code> for the save action. The form posts back to the server, where the <code>Save</code> event handler runs the INSERT statement.</p>
<img src=
Prompt
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)</p> <p> Dim sql As String = "INSERT INTO tblStk (StkSymbol, StkHigh, StkLow) VALUES (?,?,?)"</p> <p> Dim cmd As New OleDbCommand(sql, con)</p> <p> cmd.Parameters.AddWithValue("@symbol", txtSymbol.Text)</p> <p> cmd.Parameters.AddWithValue("@high", Decimal.Parse(txtHigh.Text))</p> <p> cmd.Parameters.AddWithValue("@low", Decimal.Parse(txtLow.Text))</p> <p> con.Open()</p> <p> cmd.ExecuteNonQuery()</p> <p> con.Close()</p> <p> lblStatus.Text = "Stock added successfully!"</p> <p>End Sub</p>

After the INSERT completes, the form clears the input fields and shows a brief message confirming that the stock was added. The next time the user opens the “View Stock Quotes” page, the new symbol appears in the list automatically.

Because the sample doesn’t include validation, it’s easy for users to enter invalid symbols or non‑numeric thresholds. In a production version, you’d want to add checks that ensure the symbol matches a valid ticker, that the high threshold is greater than the low threshold, and that all fields are filled. You could also catch exceptions from the database and inform the user if something goes wrong.

The add‑stock page also demonstrates how the same data‑access code can be reused across different parts of the application. The OleDbConnection object is opened, a command is executed, and the connection is closed. Because the application runs in a stateless web environment, it’s important to open the connection only when needed and to close it promptly to avoid resource leaks.

Below are screenshots showing the confirmation message and the new stock appearing in the watchlist. The design remains consistent with the rest of the app, making it easy for users to transition between pages.

Add Stock Confirmation' /></p>
<p>In a more advanced scenario, you might allow users to edit or delete existing stocks. That would involve adding additional buttons and event handlers that update or delete rows in the database. The current example keeps things simple, but the structure is ready for future expansion.</p>
<p>Having completed the add‑stock functionality, the final piece of the puzzle is ensuring that the data lives safely in the database. The next section details how the app interacts with Microsoft Access.</p><h2>Storing Stock Information in an MS Access Database</h2>
<p>The entire data layer of the application is built around a single Access file named <code>StockData.accdb</code>. Inside that file sits the <code>tblStk</code> table, which holds all user‑defined symbols and their alert thresholds. Using Access means you don’t need a separate database server; you can simply copy the .accdb file with your website or host it in a shared location.</p>
<p>The connection string for Access looks like this:</p>
<div class=
Prompt
Data Source=|DataDirectory|\StockData.accdb;Persist Security Info=False;</p>

The |DataDirectory| placeholder tells ASP.NET to look for the file in the application's root directory. Because the file is small, you can version it along with your code and deploy it with the web site.

When the application starts, it opens a connection, performs a SELECT to retrieve all rows, and then closes the connection. The same pattern is used for INSERT and UPDATE operations. The key benefit of this approach is that it keeps all data in a single, easy‑to‑manage file. The downside is that Access is not ideal for high concurrency or large datasets, but for a personal tracker that might only hold a handful of symbols, it’s more than sufficient.

The table schema is deliberately minimal. Here’s a full definition that you can create directly in Access:

Prompt
CREATE TABLE tblStk (</p> <p> StkSymbol TEXT NOT NULL,</p> <p> StkHigh NUMERIC(10,2) NOT NULL,</p> <p> StkLow NUMERIC(10,2) NOT NULL,</p> <p> PRIMARY KEY (StkSymbol)</p> <p>);</p>

Because the primary key is the symbol, duplicate entries are automatically prevented. If a user attempts to add a symbol that already exists, the INSERT will fail, and you can catch the exception to show a friendly error message.

In the application code, each interaction with the database is wrapped in a Using block (or manually opened and closed). That ensures the connection is disposed of properly, preventing file locks that could otherwise corrupt the Access database.

Although the sample uses Access, the logic can be ported to other databases with minimal changes. For instance, replacing OleDbConnection with SqlConnection and adjusting the connection string would let you switch to SQL Server or Azure SQL Database. Likewise, the OleDbDataAdapter can be replaced by a SqlDataAdapter, and the INSERT/SELECT syntax remains largely the same.

Because the application doesn’t implement user authentication, the database file is shared among all users of the web site. In a multi‑user scenario, you’d add a UserID column to tblStk and filter queries by the logged‑in user. That adds a layer of security and personalization.

Overall, the use of Access keeps the project lightweight and portable. You can run the app on any machine that has ASP.NET and the .NET Framework installed, without setting up a database server or managing connections across a network.

With the database layer in place, you now have a complete, mobile‑friendly stock quote tracker that lets you monitor your favorite symbols, receive alerts when thresholds are crossed, and add new stocks with ease - all backed by a simple Access database. Feel free to experiment, extend the logic, or replace the data store with something more robust if your needs grow. Happy coding!

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Related Articles