Wednesday, May 4, 2016

to delete the data in dataset

for (int tableno = 0; tableno < dsSMS.Tables.Count; tableno++)
                                {
                                    foreach (DataRow dr in dsSMS.Tables[tableno].Rows)
                                    {
                                        if (dr["ID"].ToString().Trim() == "24")
                                        {
                                            dr.Delete();
                                        }
                                    }
                                    dsSMS.Tables[tableno].AcceptChanges();
                                }

to find dataset has the records or not and to count the no. of records in the dataset

 bool datafound = false;
                // to check whether the data is there or not and no of rows in a dataset
                int count = 0;
                if (dsSMSJob != null && dsSMSJob.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable table in dsSMSJob.Tables)
                    {
                        if (table.Rows.Count > 0)
                        {
                            count = count + table.Rows.Count; // no. of records in dataset
                            datafound = true; // data is there
                        }
                    }
                }
                if(datafound==true)
                    sendSMS(dsSMSJob, job);     // if the data is there do some operation

json parsing

{"results":[
                {"errorCode":"28673","errorMsg":"Destination number not numeric"},
                {"errorCode":"28674","errorMsg":"Destination number empty"},
                {"errorCode":"28675","errorMsg":"Sender address empty"},
                {"errorCode":"28676","errorMsg":"SMS over 160 character, Non-compliant message"},
                {"errorCode":"28677","errorMsg":"UDH is invalid"},
                {"errorCode":"28678","errorMsg":"Coding is invalid"},
                {"errorCode":"28679","errorMsg":"SMS text is empty"},
                {"errorCode":"28680","errorMsg":"Invalid sender ID"},
                {"errorCode":"28681","errorMsg":"Invalid message, Duplicate message, Submit failed"},
                {"errorCode":"28682","errorMsg":"Invalid Receiver ID (will validate Indian mobile numbers only)"},
                {"errorCode":"28683","errorMsg":"Invalid Date time for message Schedule (If the date specified in message post for schedule delivery is less than current date or more than expiry date or more than 1 year)"}
                ]}



  var json = System.IO.File.ReadAllText(yourpath);
            //dynamic stuff = JsonConvert.DeserializeObject(json);
            JObject results = JObject.Parse(json);

            foreach (var result in results["results"])
            {
                string errorCode = (string)result["errorCode"];
                string errorMsg = (string)result["errorMsg"];
                Console.WriteLine(errorCode + ",,,....,,," + errorMsg);


            }