sqldatasource not filling in web controls
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: sqldatasource not filling in web controls

  1. #1
    Join Date
    Mar 2011
    Posts
    1

    sqldatasource not filling in web controls

    Hi

    I have a very simple example of text boxes trying to get data from sqldatasource as below;

    <%@ Page Language="C#" %>

    <script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
    SqlDataSource1.Update();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    }
    </script>
    <html>
    <head id="Head1" runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtApplicantID" runat="server"></asp:TextBox>
    <br />
    <asp:TextBox ID="txtSurname" runat="server"></asp:TextBox>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
    SelectCommand="SELECT [ApplicantID], [last_name] FROM [Applicants]" UpdateCommand="UPDATE [Applicants] SET [last_name] = @last_name WHERE [ApplicantID] = @ApplicantID">
    <UpdateParameters>
    <asp:ControlParameter Name="ApplicantID" Type="Int32" ControlID="txtApplicantID"
    PropertyName="Text" />
    <asp:ControlParameter Name="last_name" Type="String" ControlID="txtSurname" PropertyName="Text" />
    </UpdateParameters>
    </asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
    </body>
    </html>

    Problem is; the two text box controls neither get the data from nor update it back to the backend table. What could be wrong with such a simple code?

    The backend table is defined as below.

    CREATE TABLE [dbo].[Applicants](
    [ApplicantID] [int] IDENTITY(1,1) NOT NULL,
    [last_name] [nvarchar](255) NULL,
    CONSTRAINT [PK_Applicants] PRIMARY KEY CLUSTERED
    (
    [ApplicantID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    Any help to fix the two way data update issue would be appreciated.

    Many Thanks

    Regards

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center