using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace WinApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FrmTest : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dg;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbFldCategoryID;
private System.Windows.Forms.TextBox tbFldCategoryName;
private System.Windows.Forms.TextBox tbFldDescription;
private SqlConnection sqlConn = new SqlConnection("Integrated Security=SSPI; Initial Catalog=NorthWind");
DataSet ds = new DataSet();

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public FrmTest()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dg = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.tbFldCategoryID = new System.Windows.Forms.TextBox();
this.tbFldCategoryName = new System.Windows.Forms.TextBox();
this.tbFldDescription = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dg)).BeginInit();
this.SuspendLayout();
// 
// dg
// 
this.dg.DataMember = "";
this.dg.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dg.Location = new System.Drawing.Point(30, 16);
this.dg.Name = "dg";
this.dg.Size = new System.Drawing.Size(490, 424);
this.dg.TabIndex = 0;
// 
// label1
// 
this.label1.Location = new System.Drawing.Point(552, 138);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 1;
this.label1.Text = "CategoryID";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// 
// label2
// 
this.label2.Location = new System.Drawing.Point(544, 186);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 16);
this.label2.TabIndex = 2;
this.label2.Text = "CategoryName";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// 
// label3
// 
this.label3.Location = new System.Drawing.Point(536, 234);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 3;
this.label3.Text = "Description";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// 
// tbFldCategoryID
// 
this.tbFldCategoryID.AccessibleName = "Categories.CategoryID";
this.tbFldCategoryID.Location = new System.Drawing.Point(640, 136);
this.tbFldCategoryID.Name = "tbFldCategoryID";
this.tbFldCategoryID.Size = new System.Drawing.Size(112, 21);
this.tbFldCategoryID.TabIndex = 4;
this.tbFldCategoryID.Text = "";
// 
// tbFldCategoryName
// 
this.tbFldCategoryName.AccessibleName = "Categories.CategoryName";
this.tbFldCategoryName.Location = new System.Drawing.Point(640, 184);
this.tbFldCategoryName.Name = "tbFldCategoryName";
this.tbFldCategoryName.Size = new System.Drawing.Size(112, 21);
this.tbFldCategoryName.TabIndex = 5;
this.tbFldCategoryName.Text = "";
// 
// tbFldDescription
// 
this.tbFldDescription.AccessibleName = "Categories.Description";
this.tbFldDescription.Location = new System.Drawing.Point(640, 232);
this.tbFldDescription.Name = "tbFldDescription";
this.tbFldDescription.Size = new System.Drawing.Size(112, 21);
this.tbFldDescription.TabIndex = 6;
this.tbFldDescription.Text = "";
// 
// FrmTest
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(792, 473);
this.Controls.Add(this.tbFldDescription);
this.Controls.Add(this.tbFldCategoryName);
this.Controls.Add(this.tbFldCategoryID);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.dg);
this.Name = "FrmTest";
this.Text = "FrmTest";
this.Load += new System.EventHandler(this.FrmTest_Load);
((System.ComponentModel.ISupportInitialize)(this.dg)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new FrmTest());
} private void FrmTest_Load(object sender, System.EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from Categories",this.sqlConn);
da.Fill(ds, "Categories");
this.dg.DataSource = ds.Tables["Categories"];
BindTextBox();
}
代码就是这样的,调试会在da.Fill(ds, "Categories");出错,直接执行就没问题,而且我重装过系统马上安装VS2003调试也是可以的,但是安装完一些日常软件就挂了,不知道什么软件影响,急,谢谢大家帮忙了~~

解决方案 »

  1.   


    "Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=Northwind;server=(local)"
    //连接字符串
      

  2.   

    不是连接字串问题,那程序是没问题的...不知道我的VS出什么问题了,试过重装系统马上安装数据库和VS,然后调试就没问题,在安装完QQ、杀软等那些日常软件又不行了...
      

  3.   

    //connection没有关闭?
     SqlDataAdapter da = new SqlDataAdapter("select * from Categories",this.sqlConn);
                da.Fill(ds, "Categories");
                this.dg.DataSource = ds.Tables["Categories"];
                BindTextBox();
      

  4.   

    不好意思,刚才在更新试试,结果还是不行啊!!!
    提示错误是:
    未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。其他信息: 未将对象引用设置到对象的实例。再声明一次,不关代码事,代码在别的机器试过是可以的
      

  5.   

    我也觉得跟环境配置有关 或者重新编译一下dll文件。我现在也是用vs2003,vs2003确实是比较多问题,我好像也碰见过这种情况,试过很多次才搞定!
      

  6.   

    运行-》services.msc 启动服务Terminal Services 
      

  7.   

    因为你要调用系统的dll
    vs都是把dll注册到系统中去
    你打开卡巴,然后你的程序去访问那个dll。所以....