My problem is that when I click the button nothing happens to the sql server. When I look in the profiler I can see that my code reads from the database but nothing else. I have borrowed code from the internet, just so you know I'm a newbie on this Here is the code:
<script runat="server">
private void InsertShipper_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
SqlDataSource1.InsertCommand = "Insert into Shippers (CoName,phone) VALUES (@Name, @Phone)";
SqlDataSource1.InsertParameters.Add("Name", CompanyNameBox.Text);
SqlDataSource1.InsertParameters.Add("Phone", PhoneBox.Text);
SqlDataSource1.Insert();
CompanyNameBox.Text = "";
PhoneBox.Text = "";
}
protected void btnInsert_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
SqlDataSource1.InsertCommand = "Insert into Shippers (CoName,phone) VALUES (@Name, @Phone)";
SqlDataSource1.InsertParameters.Add("Name", CompanyNameBox.Text);
SqlDataSource1.InsertParameters.Add("Phone", PhoneBox.Text);
SqlDataSource1.Insert();
CompanyNameBox.Text = "";
PhoneBox.Text = "";
}
</script>
<asp:dropdownlist
id="DropDownList1"
runat="server"
datasourceid="sqlDataSource1"
datatextfield="CoName"
datavaluefield="ShipperID"/>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind %>"
selectcommand="SELECT * FROM [Shippers]" ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [Shippers] WHERE [ShipperID] = @original_ShipperID AND (([CoName] = @original_CoName) OR ([CoName] IS NULL AND @original_CoName IS NULL)) AND (([Phone] = @original_Phone) OR ([Phone] IS NULL AND @original_Phone IS NULL))"
InsertCommand="INSERT INTO [Shippers] ([ShipperID], [CoName], [Phone]) VALUES (@ShipperID, @CoName, @Phone)" OldValuesParameterFormatString="original_{0}" ProviderName="System.Data.SqlClient" UpdateCommand="UPDATE [Shippers] SET [CoName] = @CoName, [Phone] = @Phone WHERE [ShipperID] = @original_ShipperID AND (([CoName] = @original_CoName) OR ([CoName] IS NULL AND @original_CoName IS NULL)) AND (([Phone] = @original_Phone) OR ([Phone] IS NULL AND @original_Phone IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_ShipperID" Type="Int32" />
<asp:Parameter Name="original_CoName" Type="String" />
<asp:Parameter Name="original_Phone" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ShipperID" Type="Int32" />
<asp:Parameter Name="CoName" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CoName" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="original_ShipperID" Type="Int32" />
<asp:Parameter Name="original_CoName" Type="String" />
<asp:Parameter Name="original_Phone" Type="String" />
</UpdateParameters>
</asp:sqldatasource>
<br /><asp:textbox id="CompanyNameBox" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="CompanyNameBox" Display="Static"
ErrorMessage="Please enter a company name." />
<br /><asp:textbox id="PhoneBox" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
ControlToValidate="PhoneBox" Display="Static" ErrorMessage="Please enter a phone number." />
<br />
<asp:button id="Button1" runat="server" text="Insert New Shipper" onclick="InsertShipper_Click" />
<asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Button" />
</asp:Content>
btnInsert_Click
method and step through from there? Additionally: Which button do you click? Both have identical eventhandlers, why? – Serv Sep 11 '13 at 13:33<script language="c#" runat="server">
– Serv Sep 11 '13 at 13:50