protected void Insert(object sender, EventArgs e)
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
SqlConnection sqlconnection = null;
int retVal=0;
TextBox cust_id = (TextBox)GridView1.FooterRow.FindControl("txtCustId");
TextBox name = (TextBox)GridView1.FooterRow.FindControl("txtName");
TextBox state = (TextBox)GridView1.FooterRow.FindControl("txtState");
TextBox s_amount = (TextBox)GridView1.FooterRow.FindControl("txtAmnt");
TextBox sales_id = (TextBox)GridView1.FooterRow.FindControl("txtSid");
try
{
using (sqlconnection = new SqlConnection(ConnectionString))
{
sqlconnection.Open();
SqlCommand cmd = new SqlCommand("GetSubmitDetails", sqlconnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@cust_id", SqlDbType.Int).Value = cust_id.Text;
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = name.Text;
cmd.Parameters.Add("@state", SqlDbType.VarChar).Value = state.Text;
cmd.Parameters.Add("@s_amount", SqlDbType.VarChar).Value = s_amount.Text;
cmd.Parameters.Add("@sales_id", SqlDbType.Int).Value = sales_id.Text;
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
Console.WriteLine("Error reading from {0}", ex);
}
finally
{
sqlconnection.Close();
}
if (retVal == 2)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert","alert('Record Exists !!!');", true);
}
else
{
GridView1.EditIndex = -1;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert","alert('Record Saved Sucessfully');", true);
GridView1.DataBind();
GetData();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GetData();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string cust_id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string sales_id = GridView1.DataKeys[e.RowIndex].Value.ToString();
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
string ConnectionString = WebConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
SqlConnection sqlconnection = null;
try
{
using (sqlconnection = new SqlConnection(ConnectionString))
{
sqlconnection.Open();
SqlCommand cmd = new SqlCommand("GetDeleteItems", sqlconnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@cust_id", SqlDbType.Int).Value = cust_id as String;
cmd.Parameters.Add("@sales_id", SqlDbType.Int).Value = sales_id as String;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert","alert('Record Deleted Sucessfully');", true);
GetData();
}
}
catch (Exception ex)
{
Console.WriteLine("Error reading from {0}", ex);
}
finally
{
sqlconnection.Close();
}
}