没有任何错误跟警告,可是运行的时候,添加功能时候,就会显示“在位置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
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
dt = KcMedthor.KcGoodsInfoFind(GoodId, 1);
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
像这样的代码如果dt行数为零,就会出现显示“在位置0处没有任何行”,这样的错误。
if(dt.Rows.Count>0){
KcNum = Convert.ToInt32(dt.Rows[0][5].ToString());
}
return KcNum;
判断下
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;
}