in ASP.net c# program is not giving any error but data is not inserted in database blank row is inserted

i am developing a website using asp.net c#. i have one form to get branch name and branch code code is working without any error but when checked database table its adding a blank row insted of data i have given this is my add branch model with proper asp text boxes with id and name

<!-- Add Branch Modal -->
 <div class="modal fade" id="addBranchModal" tabindex="-1" role="dialog" aria-labelledby="addBranchModalLabel" aria-hidden="true">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
                 <h5 class="modal-title" id="addBranchModalLabel">Add Branch</h5>
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">×</span>
                 </button>
             </div>
             <div class="modal-body">
                 <!-- Add Branch Form -->
                 <div class="form-group">
                     <label for="branchName">Name:</label>
                     <asp:TextBox id="Brnm" runat="server" type="text" class="form-control" placeholder="Name" requaired="requaired" ></asp:TextBox>
                 </div>
                 <div class="form-group">
                     <label for="branchCode">Code:</label>

                     <asp:TextBox id="Brcd" runat="server" type="text"  class="form-control" placeholder="Code" required="required"></asp:TextBox>

                    
                 </div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary" onclick="cancelbtn()" data-dismiss="modal">Cancel</button>
                 <!-- <button type="button" class="btn btn-primary" onclick="saveBranch()">Save</button -->
                 <asp:Button ID="Button2" runat="server" Text="Save" class="btn btn-primary" OnClick="Button2_Click" UseSubmitBehavior="false"/>
             </div>
         </div>
     </div>
 </div>

and this is my backend c# code to get connected with database

protected void Button2_Click(object sender, EventArgs e)
{

    try
    {
        string connectionString = "Data Source=MSI\SQLEXPRESS;Initial Catalog=EKyc;Integrated Security=true"; // Replace with your actual connection string
        using (SqlConnection con = new SqlConnection(connectionString))
        {
            // Open the connection
            con.Open();

            string nm = Brnm.Text.Trim();
            string cd = Brcd.Text.Trim();


            // Check if connection is open
            if (con.State == ConnectionState.Open)
            {
                // Create SQL command with parameters
                SqlCommand cmd = new SqlCommand("insert into Branche (Name, Code) VALUES (@Name,@Code)", con);
                cmd.Parameters.AddWithValue("@Name", Brnm.Text.Trim()); // Assuming Brnm is the TextBox for Name
                cmd.Parameters.AddWithValue("@Code", Brcd.Text.Trim()); // Assuming Brcd is the TextBox for Code

                // Execute the command
                int rowsAffected = cmd.ExecuteNonQuery();

                // Check if insertion was successful
                if (rowsAffected > 0)
                {
                    // Insertion successful, show success message
                    Response.Write("<script>alert('Branch added successfully " + nm + " ');</script>");
                    // Optionally redirect to another page or reload current page
                    // Response.Redirect("BranchList.aspx"); // Example redirect
                }
                else
                {
                    // No rows affected, handle error
                    Response.Write("<script>alert('Error: No rows affected.');</script>");
                }
            }
            else
            {
                // Connection not opened
                Response.Write("<script>alert('Error: Database connection not open.');</script>");
            }
        }
    }
    catch (Exception ex)
    {
        // Handle exceptions
        Response.Write("<script>alert('Error: " + ex.Message + "');</script>");
        // Optionally log the exception for further investigation
        Console.WriteLine("Exception occurred: " + ex.Message);


    }

}

and this is what i have on the top of my admin page
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="EKyc.WebForm1" EnableEventValidation="false" EnableViewState="true" %>

can please someone help
this is what i see in database tableenter image description here

why is this not working?? is anything wrong with .Text property of textbox?

New contributor

Tushar Gidde is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật