实在没办法了.请各位帮忙..
public class frmAssetInfo : System.Windows.Forms.Form
{
//声明,,掠过
private DataTable dataTable=new DataTable();
public frmAssetInfo()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void frmAssetInfo_Load(object sender, EventArgs e)
{
.........
//此处给dataTable赋值
dataTable=stockBll.Select(asset);
this.assetGrid.DataSource = dataTable.DefaultView;
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
toolBar1.Buttons[1].Enabled=false;
toolBar1.Buttons[2].Enabled=false;
groupBox1.Enabled = true;
break;
case 1:
//这里无论如何都抛出异常:值不能为空,参数名:dataTable
stockBll.Update(dataTable, asset);
MessageBox.Show("更新成功!");
break;
case 2:
MessageBox.Show("删除");
break;
case 4:
if ("".Equals(txtAssetName.Text)||"".Equals(txtUnit.Text))
{
MessageBox.Show("请填写完整!");
}
else
{
assetData.AssetName = this.txtAssetName.Text;
assetData.sort = int.Parse(this.cboAssetSort.SelectedValue.ToString());
assetData.unit = this.txtUnit.Text;
assetData.type = this.txtAssetType.Text;
try
{
stockBll.Insert(assetData, asset);
MessageBox.Show("添加成功");
dataTable = stockBll.Select(asset);
assetGrid.DataSource = dataTable;
assetGrid.Update();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
break;
case 5:
toolBar1.Buttons[0].Enabled=true;
toolBar1.Buttons[1].Enabled=true;
toolBar1.Buttons[2].Enabled=true;
break;
case 7:
this.Close();
break;
}
}
}
}
大家帮忙看看,,刚学2天C#,搞了1个多小时了,还是找不到错误的原因.谢谢!