Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4574594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:56:41+00:00 2026-05-21T19:56:41+00:00

I am trying to start learning ASP.NET after a few years of PHP experience

  • 0

I am trying to start learning ASP.NET after a few years of PHP experience and I am having trouble getting the basics down.

I am just trying to insert a row into a MS SQL Server Compact 4.0 database with ASP.NET & C#. However, my page only inserts a blank row. The edit & delete functions of GridView work correctly. What am I doing wrong?

Default.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="testSite._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>People</h2>
 <p>
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowSelectButton="True" />
            <asp:BoundField DataField="first" HeaderText="first" SortExpression="first" />
            <asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:sqltestConnectionString %>" 
        DeleteCommand="DELETE FROM [People] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [People] ([first], [last]) VALUES (@first, @last)" 
        SelectCommand="SELECT * FROM [People]" 
        UpdateCommand="UPDATE [People] SET [first] = @first, [last] = @last WHERE [ID] = @ID" >
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:FormParameter Name="first" FormField="txtFirst" />
            <asp:FormParameter Name="last" FormField="txtLast" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="first" Type="String" />
            <asp:Parameter Name="last" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</p>
<p>
    <asp:Label ID="Label1" runat="server" Text="First"></asp:Label>
    <asp:TextBox ID="txtFirst" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="Label2" runat="server" Text="Last"></asp:Label>
    <asp:TextBox ID="txtLast" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="Add" />
</p>
</asp:Content>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace testSite
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            SqlDataSource1.Insert();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:56:42+00:00Added an answer on May 21, 2026 at 7:56 pm

    try this

        private List<SqlParameter> insertParameters = new List<SqlParameter>();
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlParameter fName = new SqlParameter("@First", SqlDbType.VarChar, 30);
            fName.Direction = ParameterDirection.Input;
    
            fName.Value = txtFirst.Text;
            SqlParameter lName = new SqlParameter("@Last", SqlDbType.VarChar, 30);
            lName.Direction = ParameterDirection.Input;
    
            lName.Value = txtLast.Text;
    
            insertParameters.Add(fName);
            insertParameters.Add(lName);
            SqlDataSource1.Insert();
        }
    
        protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
        {
    
            e.Command.Parameters.Clear();
    
            foreach (SqlParameter p in insertParameters)
    
                e.Command.Parameters.Add(p);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After taking a few years off from programming, I decided to start learning vb.net.
I'm trying to start a new ASP.NET Web Application Project using Visual Studio 2008.
I've just begun learning Silverlight (though I have 3 years C# experience). I'm trying
Ok I am trying to start really learning OOP style in PHP. I have
I'm trying to compile this simple program to start learning how to use timers:
I've been trying to get django set up so I can start learning it.
I start using matplotlib a month ago, so I'm still learning. I'm trying to
I'm trying to get mod_mono built and installed so I can start learning and
I'm trying to start learning C++ and I have a problem. I'm trying to
I am trying to start learning twisted for socket servers creation. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.