本文介绍了索引0为负数或高于行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
索引0为负数或高于行数。无法理解如何解决此问题:
Index 0 is either negative or above rows count. Not able to understand how to resolve this problem:
protected void loadData()
{
GlobalClass GC = new GlobalClass();
PatientID = GC.getPatientID();
string gQuery1 = "Select Treat_ID,Treat_Med_No,Treat_Due_Date,Treat_Issue_Date from Treatment_Details where Treat_P_ID = " + PatientID;
Gbind1(gQuery1);
string GetData = "Select P_Id,P_Name,P_Password,P_City,MedicineTaker, Treat_ID, Treat_Med_No,Format(Treat_Issue_Date, \"dd/mm/yyyy\") AS Treat_Issue_Date,Treat_Qty,Format(Treat_Due_Date, \"dd/mm/yyyy\") AS Treat_Due_Date,Treat_P_ID From patient_Details,Treatment_Details Where patient_Details.P_Id = Treatment_Details.Treat_P_ID AND patient_Details.P_Id = " + PatientID;
DBTrac DBT = new DBTrac();
DataSet dsData = DBT.returnDataset(GetData);
DataView dv = dsData.Tables[0].DefaultView;
dv.RowFilter = "Treat_ID >= MAX(Treat_ID)";
label1.Text = dv[0]["P_Name"].ToString();
label2.Text = dv[0]["MedicineTaker"].ToString();
label4.Text = dv[0]["P_City"].ToString();
label8.Text = dv[0]["Treat_Issue_Date"].ToString();
label11.Text = dv[0]["Treat_Due_Date"].ToString();
label14.Text = dv[0]["Treat_Qty"].ToString();
}
推荐答案
PatientID = GC.getPatientID();
构建此对象时 PatientID
在哪里设置?
DataSet dsData = DBT.returnDataset(GetData);
if(dsdata!=null && dsdata.Tables.Count>0)
{
DataView dv = dsData.Tables[0].DefaultView;
dv.RowFilter = "Treat_ID >= MAX(Treat_ID)";
if(dv!=null && dv.Table.Rows.Count>0)
{
label1.Text = dv[0]["P_Name"].ToString();
label2.Text = dv[0]["MedicineTaker"].ToString();
label4.Text = dv[0]["P_City"].ToString();
label8.Text = dv[0]["Treat_Issue_Date"].ToString();
label11.Text = dv[0]["Treat_Due_Date"].ToString();
label14.Text = dv[0]["Treat_Qty"].ToString();
}
}
这篇关于索引0为负数或高于行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!