I m the new user of ASP.NET WEB APPLICATIONS WITH C# LANGUAGE.
I m using SQL SERVER 2005 and SQLDATASOURCE to get or retrieve the data from the database.
I have created the stored procedure for insert and update.
The stored procedure is executing fine when i m running it from sqlserver2005.
My problem is with the web-application page.
I m not able to insert or update data thru that...
Pls check the code and tell me what's missing out ........
SQLDATASOURCE
<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster %>"
InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"
UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"
DeleteCommand="DELETE FROM empmaster
WHERE empid = @.empid" DeleteCommandType="Text"
SelectCommand="select * from empmaster " SelectCommandType="Text">
<InsertParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="city" />
<asp:Parameter Name="pincode" />
<asp:Parameter Name="state" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="city" />
<asp:Parameter Name="pincode" />
<asp:Parameter Name="state" />
</UpdateParameters>
</asp:SqlDataSource
GRIDVIEW
<asp:GridView ID="empGridView" runat="server" AutoGenerateColumns="False"
DataKeyNames="empid" DataSourceID="srcemp"
Width="56px" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this row ?');">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="empname"
headertext="emp Name"/>
<asp:boundfield datafield="address"
headertext="Address"/>
<asp:boundfield datafield="city"
headertext="City"/>
<asp:boundfield datafield="state"
headertext="State"/>
<asp:CheckBoxField
DataField="deleted"
HeaderText="In Existance" />
</Columns>
</asp:GridView
C# code
protected void cmdsubmit_Click(object sender, EventArgs e)
{
srcemp.InsertParameters["empname"].DefaultValue = tbcompanyname.Text;
srcemp.InsertParameters["address"].DefaultValue = tbaddress.Text;
srcemp.InsertParameters["city"].DefaultValue = tbcity.Text;
srcemp.InsertParameters["pincode"].DefaultValue = tbpincode.Text;
srcemp.InsertParameters["state"].DefaultValue = cmbstate.SelectedItem.ToString();
srcemp.Insert();
}
Note :
I m not getting a single error msg for the above code in web-page or stored procedure but it does not insert,update or delete the record from the database...
Thanxs in adv...
pls reply at earliest if possible...What's missing ??
can anyone check out..what's wrong ??
Hi,
From your code, it seems that your parameters come from TextBox and DropDownList. So you should try this way:
<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster %>"
InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"
UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"
DeleteCommand="DELETE FROM empmaster
WHERE empid = @.empid" DeleteCommandType="Text"
SelectCommand="select * from empmaster " SelectCommandType="Text">
<InsertParameters>
<asp:ControlParameter Name="empname" ControlId="tbcompanyname" PropertyName="Text"/>
<asp:ControlParameter Name="address" ControlId="tbaddress" PropertyName="Text"/>
<asp:ControlParameter Name="city" ControlId="tbcity" PropertyName="Text"/>
<asp:ControlParameter Name="pincode" ControlId="tbpincode" PropertyName="Text"/>
<asp:ControlParameter Name="state" ControlId="cmbstate" PropertyName="SelectedItem"/>
</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="empname" ControlId="tbcompanyname" PropertyName="Text"/>
<asp:ControlParameter Name="address" ControlId="tbaddress" PropertyName="Text"/>
<asp:ControlParameter Name="city" ControlId="tbcity" PropertyName="Text"/>
<asp:ControlParameter Name="pincode" ControlId="tbpincode" PropertyName="Text"/>
<asp:ControlParameter Name="state" ControlId="cmbstate" PropertyName="SelectedItem"/>
</UpdateParameters>
</asp:SqlDataSource>
In your C# code:
protected void cmdsubmit_Click(object sender, EventArgs e){
srcemp.Insert();
}
Hope this helps. Thanks.
No comments:
Post a Comment