很正常
这只不过是小异常,不会引起程序停止前进
你可以用TRY,然后CATCH,把异常打印出来

解决方案 »

  1.   

    對,你用try,catch看嘛
    try
    {}
    catch(Exception ex)
    {strMessage = ex.Message;}
      

  2.   

    把daCustomers.Fill(dsNorthwind1);前的代码贴出来看看。
      

  3.   

    daCustomers.Fill(dsNorthwind1,"这里填一个你定义的一个表名");
    这样可以这么调用
    dsNorthwind1.Tables["表名"].Rows..............
      

  4.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace DataRelationExample
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    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 System.Data.SqlClient.SqlConnection dcNorthwind;
    private System.Data.SqlClient.SqlDataAdapter daCustomers;
    private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
    private System.Data.SqlClient.SqlCommand sqlInsertCommand2;
    private System.Data.SqlClient.SqlCommand sqlUpdateCommand2;
    private System.Data.SqlClient.SqlCommand sqlDeleteCommand2;
    private System.Data.SqlClient.SqlDataAdapter daOrders;
    private System.Windows.Forms.ListBox lbOrders;
    private System.Windows.Forms.ComboBox cbCustomers;
    private DataRelationExample.dsNorthwind dsNorthwind1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
      

  5.   

    private void InitializeComponent()
    {
    this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
    this.dcNorthwind = new System.Data.SqlClient.SqlConnection();
    this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
    this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
    this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
    this.daCustomers = new System.Data.SqlClient.SqlDataAdapter();
    this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
    this.sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand();
    this.sqlUpdateCommand2 = new System.Data.SqlClient.SqlCommand();
    this.sqlDeleteCommand2 = new System.Data.SqlClient.SqlCommand();
    this.daOrders = new System.Data.SqlClient.SqlDataAdapter();
    this.lbOrders = new System.Windows.Forms.ListBox();
    this.cbCustomers = new System.Windows.Forms.ComboBox();
    this.dsNorthwind1 = new DataRelationExample.dsNorthwind();
    ((System.ComponentModel.ISupportInitialize)(this.dsNorthwind1)).BeginInit();
    this.SuspendLayout();
    // 
    // sqlSelectCommand1
    // 
    this.sqlSelectCommand1.CommandText = "SELECT sCode, sName FROM Customers";
    this.sqlSelectCommand1.Connection = this.dcNorthwind;
    // 
    // dcNorthwind
    // 
    this.dcNorthwind.ConnectionString = "data source=ZHUQIJUN;initial catalog=ZhuQiJun;persist security info=False;user id" +
    "=sa;workstation id=ZHUQIJUN;packet size=4096";
    // 
    // sqlInsertCommand1
    // 
    this.sqlInsertCommand1.CommandText = "INSERT INTO Customers(sCode, sName) VALUES (@sCode, @sName); SELECT sCode, sName " +
    "FROM Customers WHERE (sCode = @sCode)";
    this.sqlInsertCommand1.Connection = this.dcNorthwind;
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sCode", System.Data.SqlDbType.VarChar, 10, "sCode"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sName", System.Data.SqlDbType.VarChar, 20, "sName"));
    // 
    // sqlUpdateCommand1
    // 
    this.sqlUpdateCommand1.CommandText = "UPDATE Customers SET sCode = @sCode, sName = @sName WHERE (sCode = @Original_sCod" +
    "e) AND (sName = @Original_sName OR @Original_sName IS NULL AND sName IS NULL); S" +
    "ELECT sCode, sName FROM Customers WHERE (sCode = @sCode)";
    this.sqlUpdateCommand1.Connection = this.dcNorthwind;
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sCode", System.Data.SqlDbType.VarChar, 10, "sCode"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sName", System.Data.SqlDbType.VarChar, 20, "sName"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_sCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "sCode", System.Data.DataRowVersion.Original, null));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_sName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "sName", System.Data.DataRowVersion.Original, null));
    // 
    // sqlDeleteCommand1
    // 
    this.sqlDeleteCommand1.CommandText = "DELETE FROM Customers WHERE (sCode = @Original_sCode) AND (sName = @Original_sNam" +
    "e OR @Original_sName IS NULL AND sName IS NULL)";
    this.sqlDeleteCommand1.Connection = this.dcNorthwind;
    this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_sCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "sCode", System.Data.DataRowVersion.Original, null));
    this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_sName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "sName", System.Data.DataRowVersion.Original, null));
      

  6.   

    // 
    // daCustomers
    // 
    this.daCustomers.DeleteCommand = this.sqlDeleteCommand1;
    this.daCustomers.InsertCommand = this.sqlInsertCommand1;
    this.daCustomers.SelectCommand = this.sqlSelectCommand1;
    this.daCustomers.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
      new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
       new System.Data.Common.DataColumnMapping("sCode", "sCode"),
       new System.Data.Common.DataColumnMapping("sName", "sName")})});
    this.daCustomers.UpdateCommand = this.sqlUpdateCommand1;
    // 
    // sqlSelectCommand2
    // 
    this.sqlSelectCommand2.CommandText = "SELECT CustomCode, OrdCode, OrdName FROM Orders";
    this.sqlSelectCommand2.Connection = this.dcNorthwind;
    // 
    // sqlInsertCommand2
    // 
    this.sqlInsertCommand2.CommandText = "INSERT INTO Orders(CustomCode, OrdCode, OrdName) VALUES (@CustomCode, @OrdCode, @" +
    "OrdName); SELECT CustomCode, OrdCode, OrdName FROM Orders WHERE (CustomCode = @C" +
    "ustomCode) AND (OrdCode = @OrdCode)";
    this.sqlInsertCommand2.Connection = this.dcNorthwind;
    this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomCode", System.Data.SqlDbType.VarChar, 10, "CustomCode"));
    this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OrdCode", System.Data.SqlDbType.VarChar, 10, "OrdCode"));
    this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OrdName", System.Data.SqlDbType.VarChar, 20, "OrdName"));
    // 
    // sqlUpdateCommand2
    // 
    this.sqlUpdateCommand2.CommandText = @"UPDATE Orders SET CustomCode = @CustomCode, OrdCode = @OrdCode, OrdName = @OrdName WHERE (CustomCode = @Original_CustomCode) AND (OrdCode = @Original_OrdCode) AND (OrdName = @Original_OrdName OR @Original_OrdName IS NULL AND OrdName IS NULL); SELECT CustomCode, OrdCode, OrdName FROM Orders WHERE (CustomCode = @CustomCode) AND (OrdCode = @OrdCode)";
    this.sqlUpdateCommand2.Connection = this.dcNorthwind;
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomCode", System.Data.SqlDbType.VarChar, 10, "CustomCode"));
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OrdCode", System.Data.SqlDbType.VarChar, 10, "OrdCode"));
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OrdName", System.Data.SqlDbType.VarChar, 20, "OrdName"));
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomCode", System.Data.DataRowVersion.Original, null));
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OrdCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OrdCode", System.Data.DataRowVersion.Original, null));
    this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OrdName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OrdName", System.Data.DataRowVersion.Original, null));
    // 
    // sqlDeleteCommand2
    // 
    this.sqlDeleteCommand2.CommandText = "DELETE FROM Orders WHERE (CustomCode = @Original_CustomCode) AND (OrdCode = @Orig" +
    "inal_OrdCode) AND (OrdName = @Original_OrdName OR @Original_OrdName IS NULL AND " +
    "OrdName IS NULL)";
    this.sqlDeleteCommand2.Connection = this.dcNorthwind;
    this.sqlDeleteCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomCode", System.Data.DataRowVersion.Original, null));
    this.sqlDeleteCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OrdCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OrdCode", System.Data.DataRowVersion.Original, null));
    this.sqlDeleteCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OrdName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OrdName", System.Data.DataRowVersion.Original, null));
    // 
    // daOrders
    // 
    this.daOrders.DeleteCommand = this.sqlDeleteCommand2;
    this.daOrders.InsertCommand = this.sqlInsertCommand2;
    this.daOrders.SelectCommand = this.sqlSelectCommand2;
    this.daOrders.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
       new System.Data.Common.DataTableMapping("Table", "Orders", new System.Data.Common.DataColumnMapping[] {
      

  7.   

    不用貼code,你自己單步跟蹤,看一下ex.Message就知道那裡錯了.
      

  8.   

    结帖,不好意思,我自己弄错了
    zhongkeruanjian(10),sharpblade(10)