本文介绍了如何解决“位置1没有行。“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string str = "Select * from DBCUSTOMERMASTER ";


            DataTable dt = clstrans.getDataTable(str);



            grdTRANSANCTION.DataSource = dt;
            grdTRANSANCTION.DataBind();
            for (int i = 0; i <grdtransanction.rows.count;>            {
                string str2 = "select STATEMENTMENTDELIVERD  from TBLTRANSACTIONMASTER where CUSTOMERID='" + grdTRANSANCTION.Rows[i].Cells[0].Text+ "' and MONTH='" + DdlMonth.SelectedItem.Text + "' and YEAR ='" + DDLYEAR.SelectedItem.Text + "'";

                DataTable dt2 = clstrans.getDataTable(str2);
                CheckBox chk = (CheckBox)grdTRANSANCTION.Rows[i].FindControl("CHKPAYMENT");
                string str1 = dt2.Rows[i]["STATEMENTMENTDELIVERD"].ToString();
                if (str1 == "yes")
                {

                    chk.Checked = true;

                }
                else
                {
                    chk.Checked = false;
                }


            }




        }
        catch (Exception ex)
        {
            lblmessage.Text = ex.Message;
        }

推荐答案

if(dt.Rows.Count>0)
{
//Do youe Stuff
}





1)调试代码

2)检查表中是否有行 DBCUSTOMERMASTER


string str = "Select * from DBCUSTOMERMASTER ";
DataTable dt = clstrans.getDataTable(str);
grdTRANSANCTION.DataSource = dt;
grdTRANSANCTION.DataBind();

if(dt.rows.count>0)
{
  for (int i = 0; i<grdtransanction.rows.count;i++)>
{
string str2 = "select STATEMENTMENTDELIVERD from TBLTRANSACTIONMASTER where CUSTOMERID='" + grdTRANSANCTION.Rows[i].Cells[0].Text+ "' and MONTH='" + DdlMonth.SelectedItem.Text + "' and YEAR ='" + DDLYEAR.SelectedItem.Text + "'";

DataTable dt2 = clstrans.getDataTable(str2);
CheckBox chk = (CheckBox)grdTRANSANCTION.Rows[i].FindControl("CHKPAYMENT");
string str1 = dt2.Rows[i]["STATEMENTMENTDELIVERD"].ToString();
  if (str1 == "yes")
    {
     chk.Checked = true;
    }
  else
    {
     chk.Checked = false;
    }
 }
}
}
catch (Exception ex)
{
lblmessage.Text = ex.Message;
}


这篇关于如何解决“位置1没有行。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:04