CodeCharge StudioCodeCharge Studio should then automatically switch to Code view.

// Write your own code here.
` Write your own code here.
with the following:
DataAccessObject NewDao = Settings.IntranetDBDataAccessObject;
if (IsInsertMode)
{
SqlCommand userNameCmd = new SqlCommand("SELECT emp_name FROM employees " +
"WHERE emp_id=" + NewDao.ToSql(DBUtility.UserId.ToString(), FieldType.Integer), NewDao);
tasksuser_id_assign_by.Text = userNameCmd.ExecuteScalar().ToString();
}
else
{
SqlCommand userNameCmd = new SqlCommand( "SELECT emp_name FROM employees " +
"WHERE emp_id=" + NewDao.ToSql(item.user_id_assign_by.GetFormattedValue, FieldType.Integer), NewDao);
tasksuser_id_assign_by.Text = userNameCmd.ExecuteScalar().ToString();
}
Dim NewDao As DataAccessObject = Settings.IntranetDBDataAccessObject
If IsInsertMode = True Then
tasksuser_id_assign_by.Text = Convert.ToString(NewDao.ExecuteScalar( _
"SELECT emp_name FROM employees WHERE emp_id="& _
DBUtility.UserId ))
Else
tasksuser_id_assign_by.Text = Convert.ToString(NewDao.ExecuteScalar( _
"SELECT emp_name FROM employees WHERE emp_id="& _
Convert.ToString( tasksuser_id_assign_by.Text)))
End if
In the above code snippet, we have an if block which checks the value of the Boolean variable IsInsertMode. This variable is generated by CodeCharge Studio within the Before Show event of the record forms. Since the same CodeCharge Studio record form can be used to update records, delete records as well as insert new records, this variable is used to determine the state of the record form at runtime. If this variable is true, then the record form is inserting a new record, else it's either updating or deleting the record.
Both the if and else blocks define a SqlCommand object, which as discussed earlier helps you to execute commands against the database. The SQL query passed to both methods returns the name of the user stored in the emp_name field of the employees table. Once the name of the user is retrieved, it's set to the Label tasksuser_id_assign_by. The only difference between the two SQL queries is that if the user is inserting a new record i.e. the variable IsInsertMode is true, you pass the user ID of the currently logged user from the DBUtility.UserId variable. If the user is updating or deleting the record, then you pass the user ID of the user who was previously assigned the task. The user_id_assign_by property of the item object contains that value retrieved from the database.
The whole code reads approximately as follows:
Next: Add an Hidden "Assigned By" Field to Auto-Update New Tasks