GridView with objectdatasource

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;
}
}
 
W

Walter Wang [MSFT]

Hi Chuck,

If the Visible property of a row field is set to false, the row is not
displayed in the GridView control and the data for the row does not make a
round trip to the client. If you want the data for a row that is not
visible to make a round trip, add the field name to the DataKeyNames
property:

DataKeyNames="DisciplineID,RowVersion"


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top