in my code i createdstore procedureindatabase sp_updatepackageand in thewhere conditionofprocedurei
usedpackage_namewhich is thefirst textboxin aspxpackage namein this where condition i dont want toupdate package_namebecause
where conditionpackage_nameis used
so my requirement is how to update package_name without it use as where is there any change in procedure or in frontend
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication14
{
public partial class WebForm61 : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString();
hello
in my code i created store procedure in database sp_updatepackage and in the where condition of procedure i used package_name which is the first textbox in aspx package name in this where condition i dont want to update package_name because where condition package_name is used
so my requirement is how to update package_name without it use as where is there any change in procedure or in frontend
please execute them?
here is my code
aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="WebForm61.aspx.cs" Inherits="WebApplication14.WebForm61" %>
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="contentbody" runat="server">
<div >
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<tr>
<td><span style="margin-left:20px">Package name</span><br />
<span style="margin-left:20px"><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</span>
</td>
<td ><span style="margin-left:100px">Reward</span><br />
<span style="margin-left:100px"><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</span>
</td>
<td><span style="margin-left:100px">Remarks</span><br />
<span style="margin-left:100px"><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</span>
</td>
</tr>
</table>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Save" OnClick="Button2_Click" />
<asp:button ID="Button3" runat="server" Text="update" OnClick="Button3_Click" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="both"
AutoGenerateColumns="False"
DataKeyNames="tbl_id" Height="264px" Width="100%"
BorderColor="#FF0066" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Button1" runat="server" Width="25px" OnClick="Button1_Click">edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="package_name" HeaderText="Package name" />
<asp:BoundField DataField="reward" HeaderText="Reward" />
<asp:BoundField DataField="remarks" HeaderText="Remarks" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<SelectedRowStyle BackColor="#FF66FF" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
css
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication14
{
public partial class WebForm61 : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString();
public void EstablishConnection(string storeprocedure)
{
con.ConnectionString = connection;
cmd.Connection = con;
cmd.Connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storeprocedure;
}
public void CloseConnection()
{
cmd.Connection.Close();
cmd.Connection.Dispose();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FillGridview();
Button3.Visible = false;
}
}
public void FillGridview()
{
SqlDataAdapter adp = new SqlDataAdapter(" select * from tbl_package", connection);
DataTable DT = new DataTable();
adp.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
TextBox2.Text = gvr.Cells[0].Text;
TextBox3.Text = gvr.Cells[1].Text;
TextBox4.Text = gvr.Cells[2].Text;
Button2.Visible = false;
Button3.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
EstablishConnection("sp_insert_package");
cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 255).Value = TextBox2.Text;
cmd.Parameters.Add("@reward", SqlDbType.VarChar, 255).Value = TextBox3.Text;
cmd.Parameters.Add("@remarks", SqlDbType.NVarChar, 255).Value = TextBox4.Text;
cmd.Parameters.Add("@by_whom", SqlDbType.VarChar, 255).Value = "1";
cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 255).Value = System.DateTime.Now.ToString();
cmd.Parameters.Add("@status", SqlDbType.VarChar, 255).Value = "1";
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('Record Add Sucessfully');", true);
try { cmd.ExecuteNonQuery(); }
catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }
FillGridview();
con.Close();
CloseConnection();
}
protected void Button3_Click(object sender, EventArgs e)
{
EstablishConnection("sp_update_package");
cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 255).Value = TextBox2.Text;
cmd.Parameters.Add("@reward", SqlDbType.VarChar, 255).Value = TextBox3.Text;
cmd.Parameters.Add("@remarks", SqlDbType.NVarChar, 255).Value = TextBox4.Text;
cmd.Parameters.Add("@by_whom", SqlDbType.VarChar, 255).Value = "1";
cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 255).Value = System.DateTime.Now.ToString();
cmd.Parameters.Add("@status", SqlDbType.VarChar, 255).Value = "1";
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('Record Add Sucessfully');", true);
try { cmd.ExecuteNonQuery(); }
catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }
FillGridview();
con.Close();
CloseConnection();
}
}
</div> </div>}