C
Chuck P
I have a gridview with an objectdatasource which has a timestamp data field
byte[]
When I do an update my object gets passed backed to my data access layer but
the timestamp value is null (the other fields all have the edited values).
It should be the original value.
It appears that the gridview is not passing the timestamp (named RowVersion)
back.
I put the the timestamp field in the grid as a not visible field.
Is their something special I need to do?
using System.ComponentModel;
public class Discipline
{
public Discipline()
{}
public Discipline(string description,
int disciplineID,
bool isActive,
byte[] rowVersion)
{
this.Description = description;
this.DisciplineID = disciplineID;
this.IsActive = isActive;
this.RowVersion = rowVersion;
}
private string m_Description;
[DataObjectField(false, false, false, 50) ]
public string Description
{
get { return m_Description; }
set { m_Description = value; }
}
private int? m_DisciplineID;
[DataObjectField(true, true, false)]
public int? DisciplineID
{
get { return m_DisciplineID; }
set { m_DisciplineID = value; }
}
private bool m_IsActive;
[DataObjectField(false, false, false)]
public bool IsActive
{
get { return m_IsActive; }
set { m_IsActive = value; }
}
private byte[] m_RowVersion;
[DataObjectField(false, false, false)]
public byte[] RowVersion
{
get { return m_RowVersion; }
set { m_RowVersion = value; }
}
}
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;
using System.Data.Common;
using System.Data;
[DataObject]
public class lutDisciplinesDAL
{
public lutDisciplinesDAL()
{
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<Discipline> GetOne(int ID)
{
List<Discipline> Disciplines = new List<Discipline>();
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_Sel(ID);
cmd.Connection = conn;
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
int iDisciplineID = dr.GetOrdinal("DisciplineID");
int iDescription = dr.GetOrdinal("Description");
int iIsActive = dr.GetOrdinal("IsActive");
int iRowVersion = dr.GetOrdinal("RowVersion");
while (dr.Read())
{
Discipline pb = new Discipline();
pb.DisciplineID = (int)dr[iDisciplineID];
pb.Description = (string)dr[iDescription];
pb.IsActive = (bool)dr[iIsActive];
pb.RowVersion = (Byte[])dr[iRowVersion];
Disciplines.Add(pb);
}
}
}
return Disciplines;
}
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Discipline> GetAll()
{
List<Discipline> Disciplines = new List<Discipline>();
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_Sel();
cmd.Connection = conn;
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
int iDisciplineID = dr.GetOrdinal("DisciplineID");
int iDescription = dr.GetOrdinal("Description");
int iIsActive = dr.GetOrdinal("IsActive");
int iRowVersion = dr.GetOrdinal("RowVersion");
while (dr.Read())
{
Discipline pb = new Discipline();
pb.DisciplineID = (int)dr[iDisciplineID];
pb.Description = (string)dr[iDescription];
pb.IsActive = (bool)dr[iIsActive];
pb.RowVersion = (Byte[])dr[iRowVersion];
Disciplines.Add(pb);
}
}
}
return Disciplines;
}
[DataObjectMethod(DataObjectMethodType.Update, false)]
public static int UpSert(Discipline pb)
{
if ( pb.DisciplineID == null)
return Insert(pb);
else
return Update(pb);
}
[DataObjectMethod(DataObjectMethodType.Update, false)]
public static int Update(Discipline pb)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_upd(pb);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
[DataObjectMethod(DataObjectMethodType.Insert, false)]
public static int Insert(Discipline pb)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_ins(pb);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static int Delete(int DisciplineID)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_del(DisciplineID);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
private static SqlCommand web_lutDisciplines_del(int disciplineID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_del";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@DisciplineID", SqlDbType.Int);
p.Value = disciplineID;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_ins(Discipline obj)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_ins";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] p = new SqlParameter[2] ;
p[0] = new SqlParameter("@Description", SqlDbType.VarChar);
p[0].Value = obj.Description;
p[0].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[0]);
p[1] = new SqlParameter("@IsActive", SqlDbType.Bit);
p[1].Value = obj.IsActive;
p[1].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[1]);
return cmd;
}
private static SqlCommand web_lutDisciplines_Sel()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_Sel";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@GetActiveOnly", SqlDbType.Bit);
p.Value = false;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_Sel(int ID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplinesByID_Sel";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@DisciplineID", SqlDbType.Int);
p.Value = false;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_upd(Discipline obj)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_upd";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] p = new SqlParameter[4];
p[0] = new SqlParameter("@DisciplineID", SqlDbType.Int);
p[0].Value = obj.DisciplineID;
p[0].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[0]);
p[1] = new SqlParameter("@Description", SqlDbType.VarChar);
p[1].Value = obj.Description;
p[1].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[1]);
p[2] = new SqlParameter("@IsActive", SqlDbType.Bit);
p[2].Value = obj.IsActive;
p[2].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[2]);
p[3] = new SqlParameter("@RowVersion", SqlDbType.VarBinary);
p[3].Value = obj.RowVersion;
p[3].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[3]);
return cmd;
}
}
byte[]
When I do an update my object gets passed backed to my data access layer but
the timestamp value is null (the other fields all have the edited values).
It should be the original value.
It appears that the gridview is not passing the timestamp (named RowVersion)
back.
I put the the timestamp field in the grid as a not visible field.
Is their something special I need to do?
using System.ComponentModel;
public class Discipline
{
public Discipline()
{}
public Discipline(string description,
int disciplineID,
bool isActive,
byte[] rowVersion)
{
this.Description = description;
this.DisciplineID = disciplineID;
this.IsActive = isActive;
this.RowVersion = rowVersion;
}
private string m_Description;
[DataObjectField(false, false, false, 50) ]
public string Description
{
get { return m_Description; }
set { m_Description = value; }
}
private int? m_DisciplineID;
[DataObjectField(true, true, false)]
public int? DisciplineID
{
get { return m_DisciplineID; }
set { m_DisciplineID = value; }
}
private bool m_IsActive;
[DataObjectField(false, false, false)]
public bool IsActive
{
get { return m_IsActive; }
set { m_IsActive = value; }
}
private byte[] m_RowVersion;
[DataObjectField(false, false, false)]
public byte[] RowVersion
{
get { return m_RowVersion; }
set { m_RowVersion = value; }
}
}
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;
using System.Data.Common;
using System.Data;
[DataObject]
public class lutDisciplinesDAL
{
public lutDisciplinesDAL()
{
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<Discipline> GetOne(int ID)
{
List<Discipline> Disciplines = new List<Discipline>();
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_Sel(ID);
cmd.Connection = conn;
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
int iDisciplineID = dr.GetOrdinal("DisciplineID");
int iDescription = dr.GetOrdinal("Description");
int iIsActive = dr.GetOrdinal("IsActive");
int iRowVersion = dr.GetOrdinal("RowVersion");
while (dr.Read())
{
Discipline pb = new Discipline();
pb.DisciplineID = (int)dr[iDisciplineID];
pb.Description = (string)dr[iDescription];
pb.IsActive = (bool)dr[iIsActive];
pb.RowVersion = (Byte[])dr[iRowVersion];
Disciplines.Add(pb);
}
}
}
return Disciplines;
}
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Discipline> GetAll()
{
List<Discipline> Disciplines = new List<Discipline>();
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_Sel();
cmd.Connection = conn;
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
int iDisciplineID = dr.GetOrdinal("DisciplineID");
int iDescription = dr.GetOrdinal("Description");
int iIsActive = dr.GetOrdinal("IsActive");
int iRowVersion = dr.GetOrdinal("RowVersion");
while (dr.Read())
{
Discipline pb = new Discipline();
pb.DisciplineID = (int)dr[iDisciplineID];
pb.Description = (string)dr[iDescription];
pb.IsActive = (bool)dr[iIsActive];
pb.RowVersion = (Byte[])dr[iRowVersion];
Disciplines.Add(pb);
}
}
}
return Disciplines;
}
[DataObjectMethod(DataObjectMethodType.Update, false)]
public static int UpSert(Discipline pb)
{
if ( pb.DisciplineID == null)
return Insert(pb);
else
return Update(pb);
}
[DataObjectMethod(DataObjectMethodType.Update, false)]
public static int Update(Discipline pb)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_upd(pb);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
[DataObjectMethod(DataObjectMethodType.Insert, false)]
public static int Insert(Discipline pb)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_ins(pb);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static int Delete(int DisciplineID)
{
using (SqlConnection conn = new
SqlConnection(Util.DB.GetConnectionString("cnnWorkForceMobility")))
{
SqlCommand cmd = web_lutDisciplines_del(DisciplineID);
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery();
}
}
private static SqlCommand web_lutDisciplines_del(int disciplineID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_del";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@DisciplineID", SqlDbType.Int);
p.Value = disciplineID;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_ins(Discipline obj)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_ins";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] p = new SqlParameter[2] ;
p[0] = new SqlParameter("@Description", SqlDbType.VarChar);
p[0].Value = obj.Description;
p[0].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[0]);
p[1] = new SqlParameter("@IsActive", SqlDbType.Bit);
p[1].Value = obj.IsActive;
p[1].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[1]);
return cmd;
}
private static SqlCommand web_lutDisciplines_Sel()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_Sel";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@GetActiveOnly", SqlDbType.Bit);
p.Value = false;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_Sel(int ID)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplinesByID_Sel";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p;
p = new SqlParameter("@DisciplineID", SqlDbType.Int);
p.Value = false;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
return cmd;
}
private static SqlCommand web_lutDisciplines_upd(Discipline obj)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "web.lutDisciplines_upd";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] p = new SqlParameter[4];
p[0] = new SqlParameter("@DisciplineID", SqlDbType.Int);
p[0].Value = obj.DisciplineID;
p[0].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[0]);
p[1] = new SqlParameter("@Description", SqlDbType.VarChar);
p[1].Value = obj.Description;
p[1].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[1]);
p[2] = new SqlParameter("@IsActive", SqlDbType.Bit);
p[2].Value = obj.IsActive;
p[2].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[2]);
p[3] = new SqlParameter("@RowVersion", SqlDbType.VarBinary);
p[3].Value = obj.RowVersion;
p[3].Direction = ParameterDirection.Input;
cmd.Parameters.Add(p[3]);
return cmd;
}
}