// ------------------------- UserMaster.Chain ---------------------------- // chain to row by OnlineId key public virtual UserMasterRow Chain(Web.AcPage InPage, string InUserId) { UserMasterRow row = null; SqlConnection conn = null; SqlCommand cmd; SqlDataReader reader = null; bool rc; try { conn = InPage.GetDatabaseConnection( ); cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@UserId", InUserId)); cmd.CommandText = "SELECT *" + " FROM " + TableName + " WHERE UserId = @UserId"; reader = cmd.ExecuteReader(); rc = reader.Read(); // no rows if (rc == false) { throw (new UserMasterException("UserId " + InUserId + " is not found in UserMaster table")); } // got a row. extract each column from the reader. row = new UserMasterRow( ); row.UserId = reader.GetString(0); row.UserName = reader.GetString(1); } finally { if (conn != null) { conn.Close( ); } if (reader != null) { reader.Close( ); } } return(row); }
// -------------------------- Add -------------------------------- public virtual UserMasterRow Add( AcPage InPage, UserMasterRow InRow) { SqlConnection conn = null; try { conn = InPage.GetDatabaseConnection( ); SqlCommand cmd = new SqlCommand(); // assign the UserId if (InRow.UserId == null) { InRow.UserId = System.Guid.NewGuid( ).ToString( ); } cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@UserId", InRow.UserId)); cmd.Parameters.Add(new SqlParameter("@Password", InRow.Password)); cmd.Parameters.Add(new SqlParameter("@UserName", InRow.UserName)); cmd.Parameters.Add(new SqlParameter("@EmailAddress", InRow.EmailAddress)); cmd.CommandText = "Insert " + TableName + " ( " + "UserId, Password, UserName, EmailAddress ) " + "Values( @UserId, @Password, @UserName, @EmailAddress )"; cmd.ExecuteNonQuery(); } finally { if (conn != null) { conn.Close( ); } } return(InRow); }