当前位置:编程学习 > C#/ASP.NET >>

未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;


namespace c2pmag
{
/// <summary>
/// usermag 的摘要说明。
/// </summary>
public class usermag : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private DataTable UMtable = new DataTable();
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private CurrencyManager UserAmend;
private c2pmag.userDataSet DataSet;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;


private void usermag_Load(object sender, System.EventArgs e)
{

DataTable UMtable = new DataTable();
UMtable.Clear();
this.sqlDataAdapter1.Fill(UMtable);
this.dataGrid1.DataSource = UMtable.DefaultView;
DataGridStateControl();
this.textBox1.DataBindings.Add("Text",UMtable,"用户编号");
this.textBox2.DataBindings.Add("Text",UMtable,"用户积分");
this.comboBox1.DataBindings.Add("Text",UMtable,"用户权限");
UserAmend =(CurrencyManager) BindingContext[UMtable];
if(this.comboBox1.Text=="")
this.comboBox1.SelectedIndex = 0;

}
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor= Color.LightGray;
ts.MappingName=UMtable.TableName;
ts.AllowSorting=false;

this.dataGrid1.TableStyles.Add(ts);
this.dataGrid1.Select(0);
}


帮我看看吧,谢谢!! --------------------编程问答-------------------- 断点调试.. --------------------编程问答-------------------- 吧你的程序段放在 try{}catch{}段里面调试下! --------------------编程问答-------------------- this.sqlDataAdapter1.Fill(UMtable); 就是这里有错误,请问 这里是什么错误,是不是 要 将sqlDataAdapter1 实例化,但是 我已经用控件sqlDataAdapter 配置过了,还需要这么做吗 --------------------编程问答-------------------- UMtablE为空 --------------------编程问答-------------------- this.sqlDataAdapter1.Fill(UMtable); 
没有取到值 --------------------编程问答-------------------- DataTable UMtable = new DataTable(); 
UMtable.Clear(); 
this.sqlDataAdapter1.Fill(UMtable); 
//UMtable为null值出的错
--------------------编程问答-------------------- 那改如何处理?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,