i want to track member. while update the member profile old record should be in database and new record should be inserted by same member id in same table.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Data.SqlClient;
using System.Data;
using System.Xml.Linq;
using System.Configuration;
using System.Collections.Generic;
public partial class MagazineTracking_CustomerDetailsEdit : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString;
if (!IsPostBack)
{
try
{
if (Request.QueryString["Id"] != null)
{
DataTable dt = new DataTable();
int Id = Convert.ToInt32(Request.QueryString["Id"]);
string selectquery = "select Title, Name , Gender , Mobile1, Mobile2 , Phone1, Phone2 , Email1 , Address , City , State , Country , Pincode from MemberShipDetails where Id=" + Id.ToString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter(selectquery, con);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ddltitle.SelectedValue = dt.Rows[0]["Title"].ToString();
txtFName.Text = dt.Rows[0]["Name"].ToString();
txtphone1.Text = dt.Rows[0]["Phone1"].ToString();
txtphone2.Text = dt.Rows[0]["Phone2"].ToString();
txtmobile1.Text = dt.Rows[0]["Mobile1"].ToString();
txtmobile2.Text = dt.Rows[0]["Mobile2"].ToString();
txtEmail1.Text = dt.Rows[0]["Email1"].ToString();
txtMsg.Text = dt.Rows[0]["Address"].ToString();
cmbCountry.SelectedValue = dt.Rows[0]["Country"].ToString();
cmbState.SelectedValue = dt.Rows[0]["State"].ToString();
txtBCity.Text = dt.Rows[0]["City"].ToString();
TextPin.Text = dt.Rows[0]["Pincode"].ToString();
if (dt.Rows[0]["Gender"].ToString() == "Male")
{
Male.Checked = true;
}
else if (dt.Rows[0]["Gender"].ToString() == "Female")
{
Female.Checked = true;
}
}
}
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
DataTable temptable = new DataTable();
if (Request.QueryString["Id"] != null)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
int Id = Convert.ToInt32(Request.QueryString["Id"]);
//string query = "select Title, Name , Gender , Mobile1, Mobile2 , Phone1, Phone2 , Email1 , Address , City , State , Country , Pincode from MemberShipDetails where Id=" + Id.ToString();
//SqlDataAdapter sda = new SqlDataAdapter(query,con);
//sda.Fill(temptable);
string Gender;
string updatequery = "update MemberShipDetails set Title=@title,Name=@name,Address=@address,Gender=@gender,Email1=@email,Mobile1=@mobile1,Mobile2=@mobile2,Phone1=@phone1,Phone2=@phone2, City=@city,State=@state,Country=@country, Pincode=@pin where Id=" + Id.ToString();
cmd.CommandText = updatequery;
cmd.Parameters.Add("@title", ddltitle.SelectedValue.ToString().Trim());
cmd.Parameters.Add("@name", txtFName.Text.ToString().Trim());
cmd.Parameters.Add("@email",txtEmail1.Text.Trim());
cmd.Parameters.Add("@mobile1", txtmobile1.Text.Trim());
cmd.Parameters.Add("@mobile2", txtmobile2.Text.Trim());
cmd.Parameters.Add("@phone1", txtphone1.Text.Trim());
cmd.Parameters.Add("@phone2", txtphone2.Text.Trim());
if (Male.Checked)
{
Gender = "Male";
cmd.Parameters.Add("@gender", Gender);
}
else if (Female.Checked)
{
Gender = "Female";
cmd.Parameters.Add("@gender", Gender);
}
cmd.Parameters.Add("@address", txtMsg.Text.ToString());
cmd.Parameters.Add("@city", txtBCity.Text.ToString());
cmd.Parameters.Add("@state", cmbState.SelectedValue.ToString().Trim());
cmd.Parameters.Add("@country", cmbCountry.SelectedValue.ToString().Trim());
cmd.Parameters.Add("@pin", TextPin.Text.Trim());
try
{
con.Open();
cmd.ExecuteNonQuery();
// ClientScript.RegisterStartupScript(this.GetType(), "close", "closefancy();", true);
ScriptManager.RegisterStartupScript(this, this.GetType(), "Future Point", "<script language='javascript'> alert('Record inserted successfully'); parent.$.fancybox.close();</script>", false);
}
finally
{
con.Close();
// ScriptManager.RegisterStartupScript(this, this.GetType(), "Future Point", "<script language='javascript'>confirm('Are you sure to submit the record?'); parent.$.fancybox.close();</script>", false);
}
}
}
}
is it possible to execute trigger within same table because i want old and new record in same table.
I hope that column MemberId has not constraint primary key in database.
select the MemberId number to some variable and use insert command instead of update. Update Command is using for updating data. You want to insert new data to the same table with unchanged member id.
You wrote something about trigger. Do you have trigger(autoincrement) for MemerId?
atul2430
Member
145 Points
589 Posts
Update record and old record should be save in same table
Jan 24, 2013 10:26 AM|LINK
Hello friend.
i want to track member. while update the member profile old record should be in database and new record should be inserted by same member id in same table.
using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Globalization; using System.Data.SqlClient; using System.Data; using System.Xml.Linq; using System.Configuration; using System.Collections.Generic; public partial class MagazineTracking_CustomerDetailsEdit : System.Web.UI.Page { SqlConnection con = new SqlConnection(); protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString; if (!IsPostBack) { try { if (Request.QueryString["Id"] != null) { DataTable dt = new DataTable(); int Id = Convert.ToInt32(Request.QueryString["Id"]); string selectquery = "select Title, Name , Gender , Mobile1, Mobile2 , Phone1, Phone2 , Email1 , Address , City , State , Country , Pincode from MemberShipDetails where Id=" + Id.ToString(); con.Open(); SqlDataAdapter da = new SqlDataAdapter(selectquery, con); da.Fill(dt); if (dt.Rows.Count > 0) { ddltitle.SelectedValue = dt.Rows[0]["Title"].ToString(); txtFName.Text = dt.Rows[0]["Name"].ToString(); txtphone1.Text = dt.Rows[0]["Phone1"].ToString(); txtphone2.Text = dt.Rows[0]["Phone2"].ToString(); txtmobile1.Text = dt.Rows[0]["Mobile1"].ToString(); txtmobile2.Text = dt.Rows[0]["Mobile2"].ToString(); txtEmail1.Text = dt.Rows[0]["Email1"].ToString(); txtMsg.Text = dt.Rows[0]["Address"].ToString(); cmbCountry.SelectedValue = dt.Rows[0]["Country"].ToString(); cmbState.SelectedValue = dt.Rows[0]["State"].ToString(); txtBCity.Text = dt.Rows[0]["City"].ToString(); TextPin.Text = dt.Rows[0]["Pincode"].ToString(); if (dt.Rows[0]["Gender"].ToString() == "Male") { Male.Checked = true; } else if (dt.Rows[0]["Gender"].ToString() == "Female") { Female.Checked = true; } } } } catch (Exception ex) { } finally { con.Close(); } } } protected void btnSubmit_Click1(object sender, EventArgs e) { DataTable temptable = new DataTable(); if (Request.QueryString["Id"] != null) { con.ConnectionString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; int Id = Convert.ToInt32(Request.QueryString["Id"]); //string query = "select Title, Name , Gender , Mobile1, Mobile2 , Phone1, Phone2 , Email1 , Address , City , State , Country , Pincode from MemberShipDetails where Id=" + Id.ToString(); //SqlDataAdapter sda = new SqlDataAdapter(query,con); //sda.Fill(temptable); string Gender; string updatequery = "update MemberShipDetails set Title=@title,Name=@name,Address=@address,Gender=@gender,Email1=@email,Mobile1=@mobile1,Mobile2=@mobile2,Phone1=@phone1,Phone2=@phone2, City=@city,State=@state,Country=@country, Pincode=@pin where Id=" + Id.ToString(); cmd.CommandText = updatequery; cmd.Parameters.Add("@title", ddltitle.SelectedValue.ToString().Trim()); cmd.Parameters.Add("@name", txtFName.Text.ToString().Trim()); cmd.Parameters.Add("@email",txtEmail1.Text.Trim()); cmd.Parameters.Add("@mobile1", txtmobile1.Text.Trim()); cmd.Parameters.Add("@mobile2", txtmobile2.Text.Trim()); cmd.Parameters.Add("@phone1", txtphone1.Text.Trim()); cmd.Parameters.Add("@phone2", txtphone2.Text.Trim()); if (Male.Checked) { Gender = "Male"; cmd.Parameters.Add("@gender", Gender); } else if (Female.Checked) { Gender = "Female"; cmd.Parameters.Add("@gender", Gender); } cmd.Parameters.Add("@address", txtMsg.Text.ToString()); cmd.Parameters.Add("@city", txtBCity.Text.ToString()); cmd.Parameters.Add("@state", cmbState.SelectedValue.ToString().Trim()); cmd.Parameters.Add("@country", cmbCountry.SelectedValue.ToString().Trim()); cmd.Parameters.Add("@pin", TextPin.Text.Trim()); try { con.Open(); cmd.ExecuteNonQuery(); // ClientScript.RegisterStartupScript(this.GetType(), "close", "closefancy();", true); ScriptManager.RegisterStartupScript(this, this.GetType(), "Future Point", "<script language='javascript'> alert('Record inserted successfully'); parent.$.fancybox.close();</script>", false); } finally { con.Close(); // ScriptManager.RegisterStartupScript(this, this.GetType(), "Future Point", "<script language='javascript'>confirm('Are you sure to submit the record?'); parent.$.fancybox.close();</script>", false); } } } }is it possible to execute trigger within same table because i want old and new record in same table.
im my table:
id: pk
memberId should be same
kindly tell me how to do this.
i am sharing my code
Ex:
ID= 1 Memberid: A1001 name a mono: 0000 city delhi
after update
ID= 2 Memberid: A1001 name a mono: 0000 city noida
plz help me
kszymaniak
Member
205 Points
112 Posts
Re: Update record and old record should be save in same table
Jan 24, 2013 07:59 PM|LINK
I hope that column MemberId has not constraint primary key in database.
select the MemberId number to some variable and use insert command instead of update. Update Command is using for updating data. You want to insert new data to the same table with unchanged member id.
You wrote something about trigger. Do you have trigger(autoincrement) for MemerId?
Rgds