Tuesday, 13 August 2013

C# - Index was outside the bounds of the array in c#

C# - Index was outside the bounds of the array in c#

I'm trying to get all data from facebook
But I get an error
Index was outside the bounds of the array
Code:
public void Comments(string cmtid)
{
var accessToken = "***********";
var client = new FacebookClient(accessToken);
clientfeed = client.Get(cmtid).ToString();
JObject obj = JObject.Parse(clientfeed);
JArray datas = (JArray)obj["data"];
for (int i = 0; i < datas.Count; i++)
{
if (obj["data"][i]["message"] != null)
{
strPostComment = obj["data"][i]["message"].ToString();
if (strPostComment.Contains("'"))
{
strPostComment = strPostComment.Replace("'", "''");
}
strPostCommentId = obj["data"][i]["id"].ToString();
strPostCommentNameId =
obj["data"][i]["from"]["id"].ToString();
strPostCommentName =
obj["data"][i]["from"]["name"].ToString();
splitCommentId = strPostCommentId.Split('_');
strPostCommentdate =
obj["data"][i]["created_time"].ToString();
if (strPostCommentdate.Contains("T"))
{
strPostCommentdate = strPostCommentdate.Replace("T", "
");
}
abccommenttime = strPostCommentdate.Substring(0,
strPostCommentdate.ToString().Length - 5);
if (strPostCommentName == "IIPL BANK")
{
IIPLCustomer(strPostCommentNameId, abccommenttime);
}
else
{
Customer(strPostCommentNameId);
}
if (datas.Count != 0)
{
DbCommand = new OleDbCommand("select
count(response_id) from mw_response where response_id
= '" + splitCommentId[2] + "'", DbConnection);
OleDbDataReader DbReader = DbCommand.ExecuteReader();
while (DbReader.Read())
{
count = DbReader[0].ToString();
cnt = Convert.ToInt32(count);
if ((cnt == 0) && (strPostComment != ""))
{
DbCommand = new OleDbCommand("insert into
mw_response(post_id,response,response_id,
resp_date,community) values('" +
splitCommentId[1] + "','" + strPostComment +
"','" + splitCommentId[2] + "', to_date('" +
abccommenttime + "', 'yyyy-mm-dd
hh24:mi:ss'),'" + fb_community + "')",
DbConnection);
DbCommand.ExecuteNonQuery();
//update productid and customerid
DbCommand = new OleDbCommand("update
mw_response set prod_id = (select prod_id from
mw_post where post_id='" + splitCommentId[1] +
"'),customer_id = (select customer_id from
mw_customer where customer_id = '" +
strPostCommentNameId + "') where response_id =
'" + splitCommentId[2] + "'", DbConnection);
DbCommand.ExecuteNonQuery();
if (strPostCommentName != "IIPL BANK")
{
//calling comment web service
createComment(splitCommentId[2]);
}
}
}
DbReader.Close();
}
}
}
}
this is what the code terminated by Indes was outside the bounds of the array
if (datas.Count != 0)
{
DbCommand = new OleDbCommand("select count(response_id) from
mw_response where response_id = '" + splitCommentId[2] + "'",
DbConnection);
OleDbDataReader DbReader = DbCommand.ExecuteReader();
}
Any ideas? Thanks in advance.

No comments:

Post a Comment