using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 廊坊市基本信息管理系统
{
/// <summary>
/// LFQK 的摘要说明。
/// </summary>
public class LFQK : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5; private System.ComponentModel.IContainer components;
private string myconn;
    private SqlConnection mySqlConnection;
private SqlCommand mySqlCommand;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ComboBox comboBox1;
    private SqlDataReader mySqlDataReader; //private string serverName;
//private string UseID;
//private string Password;
//private string database;  
public LFQK()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
         
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void SqlConnction()
{
 this.myconn="server=localhost;database=Northwind;uid=sa;pwd=sa";
 this.mySqlConnection=new SqlConnection(myconn);
try
{
this.mySqlConnection.Open(); }
catch(SqlException ee)
{
throw ee;

}
} private void SqlCommand()
{
this.mySqlCommand=mySqlConnection.CreateCommand();
this.mySqlCommand.CommandText=mySqlCommand.CommandText;
this.mySqlCommand.CommandTimeout=30;
} private void Binding()
{
try
{
this.mySqlCommand.CommandText="select * from QKJJ";
SqlConnction();
SqlCommand();
this.mySqlDataReader=mySqlCommand.ExecuteReader();
while(this.mySqlDataReader.Read())
{
this.comboBox1.Items.Add(this.mySqlDataReader["QKJJ_TITLE"].ToString().Trim());
}
 this.mySqlConnection.Close();
 
}
catch(Exception ee)
{
MessageBox.Show(ee.Message,"出错信息",MessageBoxButtons.OK,MessageBoxIcon.Information); }
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LFQK));
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("1");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("2");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("3");
System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("4");
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.button1 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
// 
// toolBar1
// 
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(624, 41);
this.toolBar1.TabIndex = 0;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
// 
// imageList1
// 
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
// 
// toolBarButton1
// 
this.toolBarButton1.ImageIndex = 15;
this.toolBarButton1.Text = "情况简界";
// 
// toolBarButton2
// 
this.toolBarButton2.ImageIndex = 14;
this.toolBarButton2.Text = "添加";
// 
// toolBarButton3
// 
this.toolBarButton3.ImageIndex = 10;
this.toolBarButton3.Text = "列表";
// 
// toolBarButton4
// 
this.toolBarButton4.ImageIndex = 8;
this.toolBarButton4.Text = "修改";
// 
// toolBarButton5
// 
this.toolBarButton5.ImageIndex = 7;
this.toolBarButton5.Text = "删除";
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(296, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 24);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// listView1
// 
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
  listViewItem1,
  listViewItem2,
  listViewItem3,
  listViewItem4});
this.listView1.Location = new System.Drawing.Point(336, 240);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(184, 120);
this.listView1.TabIndex = 4;
// 
// comboBox1
// 
this.comboBox1.Location = new System.Drawing.Point(56, 96);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(128, 20);
this.comboBox1.TabIndex = 5;
this.comboBox1.Text = "comboBox1";
// 
// LFQK
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(624, 453);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button1);
this.Controls.Add(this.toolBar1);
this.Name = "LFQK";
this.Text = "LFQK";
this.Load += new System.EventHandler(this.LFQK_Load);
this.ResumeLayout(false); }
#endregion private void LFQK_Load(object sender, System.EventArgs e)
{

} private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{

} private void button1_Click(object sender, System.EventArgs e)
{
   Binding();
}
}
}点击按纽时候弹出对话框 未将对象引用设置到对象实列上

解决方案 »

  1.   

    主要是这段代码出错了,但找不出来!!!
                    try
    {
    this.mySqlCommand.CommandText="select * from QKJJ";
    SqlConnction();
    SqlCommand();
    this.mySqlDataReader=mySqlCommand.ExecuteReader();
    while(this.mySqlDataReader.Read())
    {
    this.comboBox1.Items.Add(this.mySqlDataReader["QKJJ_TITLE"].ToString().Trim());
    }
     this.mySqlConnection.Close();
     
    }
    catch(Exception ee)
    {
    MessageBox.Show(ee.Message,"出错信息",MessageBoxButtons.OK,MessageBoxIcon.Information); }
      

  2.   

    主要是弹出一个对话框 
    也就是这个 MessageBox.Show(ee.Message,"出错信息",MessageBoxButtons.OK,MessageBoxIcon.Information); }未将对象引用设置到对象实列上
      

  3.   

    SqlConnction();
    SqlCommand();
    ////What is This??????????
      

  4.   

    private void SqlConnction()
    {
     this.myconn="server=localhost;database=Northwind;uid=sa;pwd=sa";
     this.mySqlConnection=new SqlConnection(myconn);
    try
    {
    this.mySqlConnection.Open(); }
    catch(SqlException ee)
    {
    throw ee;

    }
    } private void SqlCommand()
    {
    this.mySqlCommand=mySqlConnection.CreateCommand();
    this.mySqlCommand.CommandText=mySqlCommand.CommandText;
    this.mySqlCommand.CommandTimeout=30;
    }
    主要就是这里的错误
    你调试一下
    单步调试
    很快就找出来了
      

  5.   

    能够运行  是抛出了异常 
    主要是弹出一个对话框 
    也就是这个MessageBox.Show(ee.Message,"出错信息",MessageBoxButtons.OK,MessageBoxIcon.Information);}未将对象引用设置到对象实列上
    呵呵  我还是新手 怎么单步调试呀  没有用过!!