很正常
这只不过是小异常,不会引起程序停止前进
你可以用TRY,然后CATCH,把异常打印出来
这只不过是小异常,不会引起程序停止前进
你可以用TRY,然后CATCH,把异常打印出来
解决方案 »
- Timercallback 程序运行一段时间后就停止了
- DataSet.ReadXml(path)方法读取XML,得不到数据?为什么啊,大侠帮忙啊,在线等?
- 关于C#的位与运算问题(&)很郁闷希望大家指点?
- 重谢! 谁能帮我完善listVied 的重绘
- c#调用有比较复杂参数的dll!!!急
- webBrowser填写好注册信息后,怎么样才能在按下提交时先执行一段代码在提交信息呀
- C#中的进度条该如何使用呢?
- 南京金碟的笔试题考专业知识吗?有谁知道?
- 如何实现排序问题
- 除了用ADO是否可以用其它的技术选数据记录吗??请大侠指教!!
- 冰天雪地,跪求各位大侠:小弟刚毕业想去广东求职学习,广东哪里有用.net做大型项目的公司吗?
- 在WebForm中如何点击一个Flash动画实现页面重定向?
try
{}
catch(Exception ex)
{strMessage = ex.Message;}
这样可以这么调用
dsNorthwind1.Tables["表名"].Rows..............
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>
{
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));
// 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[] {
zhongkeruanjian(10),sharpblade(10)