Try
organizationUri = New Uri(ConfigurationManager.AppSettings("url"))
credentials.UserName.UserName = ConfigurationManager.AppSettings("username")
credentials.UserName.Password = ConfigurationManager.AppSettings("password")
Using _serviceProxy = New OrganizationServiceProxy(organizationUri, Nothing, credentials, Nothing)
_service = DirectCast(_serviceProxy, IOrganizationService)
'Prepare SQL
Dim errorlog As String = "<fetch mapping='logical' version='1.0'>" +
" <entity name='hd_error'>" +
" <attribute name='hd_errorsource' alias='ErrorSource'/>" +
" <attribute name='hd_errmessege' alias='ErrorMessage'/>" +
"<attribute name='hd_errorevttyp' alias='ErrorType'/>" +
"<attribute name='hd_errorlogdat' alias='ErrorDate'/>" +
"<order attribute='hd_errorlogdat'/>"
If Len(value1) > 0 And Len(value2) > 0 Then
errorlog = errorlog & "<filter>" +
" <condition attribute='hd_errorlogdat'operator='on-or-after' value='2016-09-06' />" +
"<condition attribute='hd_errorlogdat' operator='on-or-before' value='2016-09-06' />" +
"</filter>"
End If
errorlog = errorlog & "</entity>" +
" </fetch>"
Dim queryResult = _service.RetrieveMultiple(New FetchExpression(errorlog))
Try
dt.Columns.Add("SlNo", GetType(System.String))
dt.Columns.Add("ErrorSource", GetType(System.String))
dt.Columns.Add("ErrorMessage", GetType(System.String))
dt.Columns.Add("ErrorType", GetType(System.String))
dt.Columns.Add("ErrorDate", GetType(System.String))
' Populate the DataTable
'
'Dim drDSRow As DataRow
Dim drNewRow As DataRow
For Each item In queryResult.Entities
Dim errsource As String = DirectCast(item("ErrorSource"), AliasedValue).Value.ToString()
Dim errmess As String = DirectCast(item("ErrorMessage"), AliasedValue).Value.ToString()
Dim errtyp As String = DirectCast(item("ErrorType"), AliasedValue).Value.ToString()
Dim errdate As String = DirectCast(item("ErrorDate"), AliasedValue).Value.ToString()
drNewRow = dt.NewRow()
drNewRow("SlNo") = ctr
drNewRow("ErrorSource") = errsource
drNewRow("ErrorMessage") = errmess
drNewRow("ErrorType") = errtyp
drNewRow("ErrorDate") = errdate
dt.Rows.Add(drNewRow)
ctr = ctr + 1
Next