Building an E-Commerce Chatbot in ASP.NET Using SQL Server

Chatbots are powerful tools for improving user experience on digital platforms. In this blog, I’ll take you through how I created a simple e-commerce chatbot using ASP.NET (Web Forms) and SQL Server that helps users get instant answers about digital products like planners, templates, and file types without using any third-party AI libraries.

What does this Chatbot do?

  • Responds to product-related user queries using predefined keywords
  • Displays a friendly chat UI with user-bot interaction
  • Store each conversation in a chat log table for analysis
  • Uses SQL queries to retrieve responses based on keyword match
  • Fully functional without JavaScript or AJAX

Tech Stack

  • Frontend: ASP.NET Web Forms, Bootstrap 5
  • Backend: C# (.NET Framework), ADO.NET
  • Database: Microsoft SQL Server
  • Tables Used
    • BootResponses: Stores bot responses
    • ChatLogs: Stores chat history

UI Design (ChatBoot.aspx)

The chatbot is placed inside a styled Bootstrap card. Here's the code.

<div class="chat-wrapper">
    <div class="chat-header">
        <h5>E-Commerce Chatbot - Ask Me About Products!</h5>
    </div>
    
    <div class="chat-body" id="chatBody" runat="server">
    </div>
    
    <div class="chat-footer">
        <asp:TextBox 
            ID="txtUserInput" 
            runat="server" 
            CssClass="form-control" 
            placeholder="Type your question...">
        </asp:TextBox>
        
        <asp:Button 
            ID="btnSend" 
            runat="server" 
            Text="Send" 
            CssClass="btn btn-primary" 
            OnClick="btnSend_Click" />
    </div>
</div>

Here’s how the UI looks.

Screenshots

Ui

Backend Logic (ChatBoot.aspx.cs)

On Page_Load, I show a friendly welcome message and sample questions.

chatBody.InnerHtml += @"
<div class='bot-msg'>
    Welcome! I'm your assistant bot for digital product shopping and selling.<br/>
    Try asking:
    <ul>
        <li>What templates do you have?</li>
        <li>How to list my product?</li>
        <li>Steps to buy a planner?</li>
    </ul>
</div>";

When the user clicks "Send", the bot checks the database for matching keywords.

string query = @"
    SELECT TOP 1 ResponseText 
    FROM BootResponses 
    WHERE @msg LIKE '%' + QuestionKeyword + '%'";

If a match is found, the bot replies with that message. Else, it shows a fallback message.

Also, both user messages and bot replies are logged into an SQL table ChatLogs.

SQL table ChatLogs

Chatboot

Database Structure

BootResponses Table

Id QuestionKeyword ResponseText
1 Price Our digital product prices start at just $5.
2 Template We offer a variety of templates including resumes, portfolios, and business plans.
3 Hello Hi there! Welcome to our Digital Marketplace. How can I assist you today?
4 Hi Hello! I’m your Assistant bot. Ask me anything about our Digital Products.

It supports flexible keywords like "Price", "Template", "Upload", "Download", "Support", "Account", and many more.

ChatLogs Table

This logs every user query and bot reply for future review or enhancement.

Id UserMessage BotResponse Timestamp
1 How to buy and sell the digital product I'm sorry, I don't understand. 2025-04-29 16:09:58
2 How to create an Account? You can register a free account to manage your purchases and downloads. 2025-04-29 16:22:15

Highlights

  • Keyword Matching: Uses SQL LIKE to match partial questions.
  • Data Logging: Every conversation is stored in ChatLogs.
  • Responsive UI: Built with Bootstrap for a clean mobile-friendly interface.
  • Expandable: Easily add more QuestionKeyword and ResponseText entries.

Future Enhancements

  • Add AJAX to make the chatbot work without page refresh.
  • Train a basic ML model to better understand fuzzy queries.
  • Show suggestions dynamically as the user types.
  • Include voice-based input for accessibility.

Final Thoughts

This chatbot project demonstrates how even a basic keyword-based bot can serve as an interactive assistant for digital product platforms. It’s a great starting point if you're building your own chatbot and want to connect frontend UI with backend logic and a real database.

Output

Product