DataTable GetSforceData(string strSQL, int iBatchSize)
{
DataTable dt = null;
partner.SforceService binding = new partner.SforceService();
string strAccountName = "", strAccountPassword = "", strSecurityToken = "";
//get account name, account password and security token here
bll = null;
partner.LoginResult lr = binding.login(strAccountName,
strAccountPassword + strSecurityToken);
if (!lr.passwordExpired)
{
binding.Url = lr.serverUrl;
binding.SessionHeaderValue = new partner.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
partner.QueryResult qr = null;
binding.QueryOptionsValue = new partner.QueryOptions();
binding.QueryOptionsValue.batchSize = iBatchSize;
binding.QueryOptionsValue.batchSizeSpecified = true;
qr = binding.query(strSQL);
bool done = false;
if (qr.size > 0)
{
dt = new DataTable();
partner.sObject sOtmp = (partner.sObject)qr.records[0];
for (int i = 0; i < sOtmp.Any.Length; i++)
{
dt.Columns.Add(sOtmp.Any[i].LocalName);
}
string[] prValues = new string[sOtmp.Any.Length];
while (!done)
{
for (int i = 0; i < qr.records.Length; i++)
{
sOtmp = (partner.sObject)qr.records[i];
for (int j = 0; j < sOtmp.Any.Length; j++)
{
if (sOtmp.Any[j].ChildNodes.Count > 1)
{
prValues.SetValue(sOtmp.Any[j].ChildNodes[2].InnerText, j);
}
else
{
prValues.SetValue(sOtmp.Any[j].InnerText, j);
}
}
dt.Rows.Add(prValues);
}
if (qr.done)
{
done = true;
}
else
{
qr = binding.queryMore(qr.queryLocator);
}
}
}
}
return dt;
}
Coding is one of my job from 2001. I have written codes for many projects but I cannot remember all of them. I hope this blog help me do that.
Comments
Post a Comment