when trying to save data in loop its skip 1 row.
date ins_amt paid mrno paid status
1 09-Dec-16 16800 16800 11 NULL 1
2 09-Jan-17 16800 16800 11 NULL 1
3 09-Feb-17 17220 17220 11 NULL 1
4 09-Mar-17 17220 0 NULL `enter code here`
5 26-Feb-17 17220 30 NULL
i want my data should save like this:-
date ins_amt paid mrno paid status
1 09-Dec-16 16800 16800 11 NULL 1
2 09-Jan-17 16800 16800 11 NULL 1
3 09-Feb-17 17220 17220 11 NULL 1
4 09-Mar-17 17220 30 NULL
5 26-Feb-17 17220 0 NULL
假设我想以付费方式保存50850。首先它应检查ins_amt如果ins_amt> 50850然后第一行支付amt应该是16800然后50850-16800休息应该是下一行,直到它满足标准如果ins_amt<鉴于amt应该在下一行。 但在我的代码中,上一次余额跳过1行。
Int64 third = ((Convert.ToInt64(instamt.Text)));// eg:- 50850
SqlConnection con = new SqlConnection(connString);
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter("select pflno,pfname,insno,insdate,insamt,lastpaid from repaysec where pflno = '" + Label1.Text + "'and (paid = '' or paid is null) order by cast([insdate] as datetime) asc", con);
dt21.Clear();
adapt.Fill(dt21);
con.Close();
DataTable table = dt21;
foreach (DataRow row in table.Rows) // Loop over the rows.
{
Int64.Parse(row[4].ToString());
Int64 first = Int64.Parse(row[4].ToString());
Int64 second = Int64.Parse(row[5].ToString());
third = second + third;
if (first < third)
{
SqlCommand cmd = new SqlCommand("update repaysec set lastpaid=@lastpaid,paid=@paid,mrno=@mrno where pflno=@pflno and insno=@insno and insdate=@insdate", con);
{
cmd.Parameters.AddWithValue("@pflno", Label1.Text);
cmd.Parameters.AddWithValue("@insno", row[2].ToString());
cmd.Parameters.AddWithValue("@insdate", row[3].ToString());
cmd.Parameters.AddWithValue("@lastpaid", first);
cmd.Parameters.AddWithValue("@mrno", ct.ToString());
cmd.Parameters.AddWithValue("@paid", "1");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
third = third - first;
third = second + third;
}
}
else if (first > third)
{
SqlCommand cmd = new SqlCommand("update repaysec set lastpaid=@lastpaid,paid=@paid where pflno=@pflno and insno=@insno and insdate=@insdate", con);
{
cmd.Parameters.AddWithValue("@pflno", Label1.Text);
cmd.Parameters.AddWithValue("@insno", row[2].ToString());
cmd.Parameters.AddWithValue("@insdate", row[3].ToString());
cmd.Parameters.AddWithValue("@lastpaid", third);
cmd.Parameters.AddWithValue("@paid", "");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
third = 0;
}
break;
}
else if (first == third)
{
third = second + third;
SqlCommand cmd = new SqlCommand("update repaysec set lastpaid=@lastpaid,paid=@paid,mrno=@mrno where pflno=@pflno and insno=@insno and insdate=@insdate", con);
{
cmd.Parameters.AddWithValue("@pflno", Label1.Text);
cmd.Parameters.AddWithValue("@insno", row[2].ToString());
cmd.Parameters.AddWithValue("@insdate", row[3].ToString());
cmd.Parameters.AddWithValue("@lastpaid", third);
cmd.Parameters.AddWithValue("@mrno", ct.ToString());
cmd.Parameters.AddWithValue("@paid", "1");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
third = 0;
}
break;
}
}
}