Advertisement

05.14.2008 at 11:04AM PDT, ID: 23402484 | Points: 500
[x]
Attachment Details

Inserting values to  SQL Exp DB from a text box on button command

Asked by adamhealy in Programming for ASP.NET, C# Programming Language, Visual Studio 2008

Tags: ASP.Net 3.5, C#

I am trying to update a SQL Express DB table with data from a ASP.Net page. The code is below. I need some help with how to properly bind the text box to the SQL Insert Query and how to execute the insert on button click.

I am using VS 2008.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<div style="height: 375px">
 
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true"></asp:TextBox>
 
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnStrLiberty %>" 
        InsertCommand="INSERT INTO [test] ([test1]) VALUES (@test1)" 
        ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [test] WHERE [test1] = @original_test1" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT [test1] FROM [test] WHERE ([test1] = @test1)">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="test1" PropertyName="Text" 
                Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_test1" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="test1" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
 
</div>
 
Loading Advertisement...
 
[+][-]05.15.2008 at 01:07AM PDT, ID: 21571435

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 03:21AM PDT, ID: 21572021

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 03:30AM PDT, ID: 21572055

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 10:24AM PDT, ID: 21576094

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628