Here is how to add columns to a datatable. You can also set the Ordinal Position when you add it, to rearrange to order of the columns.
If the datatable has been attached to a datagridview and then you add the columns, you need to set the datagridview.datasource=null and the refresh the grid. Then add the columns and reattach the datatable to the gridview and refresh it.
If you do not disconnect and reconnect, the new fields will show up, but they will appear at the end of the display.
[code]
public void AddCertColumns(DataTable vdt)
{
if (!vdt.Columns.Contains("Certificate"))
{
vdt.Columns.Add("Certificate", Type.GetType("System.String")).SetOrdinal(0);
}
if (!vdt.Columns.Contains("BatchNum"))
{
vdt.Columns.Add("BatchNum", Type.GetType("System.String")).SetOrdinal(1);
}
if (!vdt.Columns.Contains("CancelEntryDate"))
{
vdt.Columns.Add("CancelEntryDate", Type.GetType("System.String")).SetOrdinal(2);
}
}
[/code]
Thursday, December 19, 2013
Wednesday, December 11, 2013
SISendMail using *user in an email field in the web.config
I added the option to specify *user as an email address in the rptEmailConf procedures. The routines will see *user and translate the email address to the current user.
To utilize this feature you must specify the SISendMail.UserEmail before sending the email. The programs use the UserEmail to substitute for the *user at the appropriate time.
This will allow programs to have entries in the web.config file, but to send to the user invoking the program without having to specify a distribution list. If a distribution list is needed in the future, the web.config can be modified with the email entries without having to modify the report program.
To utilize this feature you must specify the SISendMail.UserEmail before sending the email. The programs use the UserEmail to substitute for the *user at the appropriate time.
This will allow programs to have entries in the web.config file, but to send to the user invoking the program without having to specify a distribution list. If a distribution list is needed in the future, the web.config can be modified with the email entries without having to modify the report program.
Tuesday, December 10, 2013
Handling updates on a Form When Threads Are Involved
[code]
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub ThreadProcSafe(ByVal vMessage As String, Optional ByVal vMessage2 As String = "")
' Check if this method is running on a different thread
' than the thread that created the control.
If lstActions.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {Now.ToString() + "-" + vMessage + " " + vMessage2})
Else
' It's on the same thread, no need for Invoke.
lstActions.Items.Add(Now.ToString() + "-" + vMessage + " " + vMessage2)
End If
End Sub
Private Sub SetText(ByVal vMessage As String)
lstActions.Items.Add(vMessage)
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub ThreadProcSafe(ByVal vMessage As String, Optional ByVal vMessage2 As String = "")
' Check if this method is running on a different thread
' than the thread that created the control.
If lstActions.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {Now.ToString() + "-" + vMessage + " " + vMessage2})
Else
' It's on the same thread, no need for Invoke.
lstActions.Items.Add(Now.ToString() + "-" + vMessage + " " + vMessage2)
End If
End Sub
Private Sub SetText(ByVal vMessage As String)
lstActions.Items.Add(vMessage)
End Sub
[/code]
There are issues when trying to update a form from a delegate or a different thread in a program. To access the form fields, you need to use something like the code above to make it "threadsafe" so that it will work.
My original program that uses this technique is the FolderWatcher project.
Handling Errors with MYSQL replication where we want to bypass a few events that cause replication to stop
I have run into situations where I have set up some data on a replicated server, that only relates to that server, but causes replication to stop if the main server tries to update data that is not on the replicated server.
To check to slave status;
Go to the console and enter
show slave status;
This will show the state of the slave.
If you need to bypass and event in the replication log, you can use this statement to bypass a record or number of records:
To check to slave status;
Go to the console and enter
show slave status;
This will show the state of the slave.
If you need to bypass and event in the replication log, you can use this statement to bypass a record or number of records:
SET GLOBAL sql_slave_skip_counter = N
Issue this command and then use this command to restart the slave:
start slave;
show slave status;
Repeat as many times as needed to bypass the records that cause a problem.
Subscribe to:
Posts (Atom)