技术,高手帮忙,在位置0处没有任何行?
没有任何错误跟警告,可是运行的时候,添加功能时候,就会显示“在位置0处没有任何行”,麻烦高手帮下忙,详细点哈~~菜鸟的我using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JXCCManage.ClassInfo;
using JXCCManage.GoodMenhod;
using System.Data.SqlClient;
namespace JXCCManage
{
public partial class frmSellGoods : Form
{
string js = "";
public string kcId = "";
public string GoodId = null;
tb_SellGoods sellGoods = null;
DataTable dt = null;
tb_SellGoodsMenthod SellMedthor = null;
AutoSetId aid = null;
tb_KcGoodsMenthod KcMedthor = null;
public static int intFalg;
public frmSellGoods(string js)
{
InitializeComponent();
sellGoods = new tb_SellGoods();
SellMedthor = new tb_SellGoodsMenthod();
aid = new AutoSetId();
this.js = js;
KcMedthor = new tb_KcGoodsMenthod();
this.ActiveControl = txtGoodsName;
this.KeyPreview = true;
}
/// <summary>
/// 获取进货量
/// </summary>
/// <returns></returns>
//private int GetSpLiang()
//{
// int num;
// DataTable dt = new DataTable();
// dt = KcMedthor.KcGoodsInfoFind(GoodId,1);
// num =Convert.ToInt32(dt.Rows[0][4].ToString());
// return num;
//}
/// <summary>
/// 获取库存量
/// </summary>
/// <returns></returns>
private int GetKcLiang()
{
int KcNum;
DataTable dt = new DataTable();
dt = KcMedthor.KcGoodsInfoFind(GoodId, 1);
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
return KcNum;
}
/// <summary>
/// 更新库存数量
/// </summary>
private void UpdateKcLiang()
{
int OrginKcLiang, CurrentKcLiang;
OrginKcLiang = GetKcLiang();
int SellNum = Convert.ToInt32(txtSellNum.Text);
try
{
if (SellNum < OrginKcLiang)
{
if (SellMedthor.SellGoodsInfoInert(sellGoods) == 1)
{
MessageBox.Show("添加成功!");
intFalg = 0;
FillDataGrid();
ClearControl();
ControlStatus();
}
else
{
MessageBox.Show("添加失败!");
ControlStatus();
intFalg = 0;
}
CurrentKcLiang = OrginKcLiang - SellNum;
int i = KcMedthor.KcGoodsInfoUpdate(GoodId, CurrentKcLiang);
if (i > 0)
{
MessageBox.Show("库存事实更新成功!");
}
}
else
{
MessageBox.Show(SellNum.ToString() + ">库存数量!", "提示");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
//用回车完成Tab的功能,使用onkeypress
--------------------编程问答-------------------- http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=788&bih=475&q=%E5%9C%A8%E4%BD%8D%E7%BD%AE0%E5%A4%84%E6%B2%A1%E6%9C%89%E4%BB%BB%E4%BD%95%E8%A1%8C&aq=f&aqi=&aql=&oq= --------------------编程问答-------------------- DataTable的使用原则一般是“先判断后使用”,除非你保证dt.ROWS.count一定大于零。
dt = KcMedthor.KcGoodsInfoFind(GoodId, 1);
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
像这样的代码如果dt行数为零,就会出现显示“在位置0处没有任何行”,这样的错误。 --------------------编程问答-------------------- 没查出数据来 --------------------编程问答-------------------- dt = KcMedthor.KcGoodsInfoFind(GoodId, 1);
if(dt.Rows.Count>0){
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
}
return KcNum;
判断下 --------------------编程问答-------------------- DataTable 为空。 --------------------编程问答-------------------- DataTable没数据 --------------------编程问答-------------------- 修改后的。
if (dt != null && dt.Rows.Count > 0)
/// <summary>
/// 获取库存量
/// </summary>
/// <returns></returns>
private int GetKcLiang()
{
int KcNum;
DataTable dt = new DataTable();
dt = KcMedthor.KcGoodsInfoFind(GoodId, 1);
if (dt != null && dt.Rows.Count > 0)
{
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
}
return KcNum;
}
补充:.NET技术 , C#