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调试也是可以的,但是安装完一些日常软件就挂了,不知道什么软件影响,急,谢谢大家帮忙了~~
解决方案 »
- 在DataGridView中用DataAdapter和CommmandBuilder怎么实现不了对数据库的修改
- c# 中ftp 编程中,判断ftp 服务器上某个目录是否存在的命令是什么?^_^
- c#小问题
- 通过socket传文件,服务器端无核判断文件类型?
- 请教exif的读取和修改
- 短信网关SP端
- 请教: 如何固定DataGrid中列的宽度?
- mysql参数化查询语句问题
- 100分,求获取分页(同一主题多页)网页内容.....
- 怎样实现在水晶报表中打印类似发票的表,还要每页有(正副)两份,还有,水晶报表不能实现把数字金额转换为大写的金额?
- 请教FileStream处理隐藏文件的问题
- 泛型集合里如何使用泛型元素
"Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=Northwind;server=(local)"
//连接字符串
SqlDataAdapter da = new SqlDataAdapter("select * from Categories",this.sqlConn);
da.Fill(ds, "Categories");
this.dg.DataSource = ds.Tables["Categories"];
BindTextBox();
提示错误是:
未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。其他信息: 未将对象引用设置到对象的实例。再声明一次,不关代码事,代码在别的机器试过是可以的
vs都是把dll注册到系统中去
你打开卡巴,然后你的程序去访问那个dll。所以....