在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 读写access数据库

C# 读写access数据库

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.21M
  • 下载次数:319
  • 浏览次数:3368
  • 发布时间:2015-09-30
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 数据库 Access C# access数据库 c

实例介绍

【实例简介】
【实例截图】

【核心代码】


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
 
namespace MyDB
{
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.Button button6;
        private System.Windows.Forms.Button button7;
        private System.Windows.Forms.Button button8;
        private System.Windows.Forms.Button button9;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox4;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox textBox5;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox textBox6;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.TextBox textBox7;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.TextBox textBox8;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.TextBox textBox9;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.TextBox textBox10;
        private System.Windows.Forms.Label label10;
        private System.Windows.Forms.TextBox textBox11;
        private System.Windows.Forms.Label label11;
        private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
        private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
        private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
        private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
        private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
        private System.Data.OleDb.OleDbConnection oleDbConnection1;
        private BindingManagerBase MyBind;
        private System.Data.OleDb.OleDbCommand oleDbCommand1;
        private System.Data.DataSet dataSet1;
         
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.Container components = null;
 
        public Form1()
        {
            //
            // 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.groupBox1 = new System.Windows.Forms.GroupBox();
            this.textBox9 = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.textBox10 = new System.Windows.Forms.TextBox();
            this.label10 = new System.Windows.Forms.Label();
            this.textBox11 = new System.Windows.Forms.TextBox();
            this.label11 = new System.Windows.Forms.Label();
            this.textBox8 = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.textBox7 = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.textBox6 = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.textBox5 = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.textBox4 = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.button7 = new System.Windows.Forms.Button();
            this.button8 = new System.Windows.Forms.Button();
            this.button9 = new System.Windows.Forms.Button();
            this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
            this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
            this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
            this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
            this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
            this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
            this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
            this.dataSet1 = new System.Data.DataSet();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
            this.SuspendLayout();
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.textBox9);
            this.groupBox1.Controls.Add(this.label9);
            this.groupBox1.Controls.Add(this.textBox10);
            this.groupBox1.Controls.Add(this.label10);
            this.groupBox1.Controls.Add(this.textBox11);
            this.groupBox1.Controls.Add(this.label11);
            this.groupBox1.Controls.Add(this.textBox8);
            this.groupBox1.Controls.Add(this.label8);
            this.groupBox1.Controls.Add(this.textBox7);
            this.groupBox1.Controls.Add(this.label7);
            this.groupBox1.Controls.Add(this.textBox6);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.textBox5);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.Controls.Add(this.textBox4);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.textBox3);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.textBox2);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.textBox1);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(8, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(352, 224);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "数据库信息";
            //
            // textBox9
            //
            this.textBox9.Location = new System.Drawing.Point(232, 192);
            this.textBox9.Name = "textBox9";
            this.textBox9.Size = new System.Drawing.Size(112, 21);
            this.textBox9.TabIndex = 21;
            this.textBox9.Text = "";
            //
            // label9
            //
            this.label9.Location = new System.Drawing.Point(184, 200);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(48, 16);
            this.label9.TabIndex = 20;
            this.label9.Text = "传真:";
            //
            // textBox10
            //
            this.textBox10.Location = new System.Drawing.Point(72, 192);
            this.textBox10.Name = "textBox10";
            this.textBox10.Size = new System.Drawing.Size(104, 21);
            this.textBox10.TabIndex = 19;
            this.textBox10.Text = "";
            //
            // label10
            //
            this.label10.Location = new System.Drawing.Point(8, 200);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(48, 16);
            this.label10.TabIndex = 18;
            this.label10.Text = "电话:";
            //
            // textBox11
            //
            this.textBox11.Location = new System.Drawing.Point(232, 168);
            this.textBox11.Name = "textBox11";
            this.textBox11.Size = new System.Drawing.Size(112, 21);
            this.textBox11.TabIndex = 17;
            this.textBox11.Text = "";
            //
            // label11
            //
            this.label11.Location = new System.Drawing.Point(184, 176);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(48, 16);
            this.label11.TabIndex = 16;
            this.label11.Text = "国家:";
            //
            // textBox8
            //
            this.textBox8.Location = new System.Drawing.Point(72, 168);
            this.textBox8.Name = "textBox8";
            this.textBox8.Size = new System.Drawing.Size(104, 21);
            this.textBox8.TabIndex = 15;
            this.textBox8.Text = "";
            //
            // label8
            //
            this.label8.Location = new System.Drawing.Point(8, 176);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(72, 16);
            this.label8.TabIndex = 14;
            this.label8.Text = "邮政编码:";
            //
            // textBox7
            //
            this.textBox7.Location = new System.Drawing.Point(232, 144);
            this.textBox7.Name = "textBox7";
            this.textBox7.Size = new System.Drawing.Size(112, 21);
            this.textBox7.TabIndex = 13;
            this.textBox7.Text = "";
            //
            // label7
            //
            this.label7.Location = new System.Drawing.Point(184, 152);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(48, 16);
            this.label7.TabIndex = 12;
            this.label7.Text = "地区:";
            //
            // textBox6
            //
            this.textBox6.Location = new System.Drawing.Point(72, 144);
            this.textBox6.Name = "textBox6";
            this.textBox6.Size = new System.Drawing.Size(104, 21);
            this.textBox6.TabIndex = 11;
            this.textBox6.Text = "";
            //
            // label6
            //
            this.label6.Location = new System.Drawing.Point(8, 152);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(48, 16);
            this.label6.TabIndex = 10;
            this.label6.Text = "城市:";
            //
            // textBox5
            //
            this.textBox5.Location = new System.Drawing.Point(88, 120);
            this.textBox5.Name = "textBox5";
            this.textBox5.Size = new System.Drawing.Size(256, 21);
            this.textBox5.TabIndex = 9;
            this.textBox5.Text = "";
            //
            // label5
            //
            this.label5.Location = new System.Drawing.Point(8, 128);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(72, 16);
            this.label5.TabIndex = 8;
            this.label5.Text = "联系地址:";
            //
            // textBox4
            //
            this.textBox4.Location = new System.Drawing.Point(88, 96);
            this.textBox4.Name = "textBox4";
            this.textBox4.Size = new System.Drawing.Size(256, 21);
            this.textBox4.TabIndex = 7;
            this.textBox4.Text = "";
            //
            // label4
            //
            this.label4.Location = new System.Drawing.Point(8, 104);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(80, 16);
            this.label4.TabIndex = 6;
            this.label4.Text = "联系人头衔:";
            //
            // textBox3
            //
            this.textBox3.Location = new System.Drawing.Point(88, 72);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(256, 21);
            this.textBox3.TabIndex = 5;
            this.textBox3.Text = "";
            //
            // label3
            //
            this.label3.Location = new System.Drawing.Point(8, 80);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(80, 16);
            this.label3.TabIndex = 4;
            this.label3.Text = "联系人姓名:";
            //
            // textBox2
            //
            this.textBox2.Location = new System.Drawing.Point(88, 48);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(256, 21);
            this.textBox2.TabIndex = 3;
            this.textBox2.Text = "";
            //
            // label2
            //
            this.label2.Location = new System.Drawing.Point(8, 56);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(72, 16);
            this.label2.TabIndex = 2;
            this.label2.Text = "公司名称:";
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(88, 24);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(256, 21);
            this.textBox1.TabIndex = 1;
            this.textBox1.Text = "";
            //
            // label1
            //
            this.label1.Location = new System.Drawing.Point(8, 32);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 16);
            this.label1.TabIndex = 0;
            this.label1.Text = "客户ID:";
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(368, 16);
            this.button1.Name = "button1";
            this.button1.TabIndex = 1;
            this.button1.Text = "第一条记录";
            this.button1.Click  = new System.EventHandler(this.button1_Click);
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(368, 40);
            this.button2.Name = "button2";
            this.button2.TabIndex = 2;
            this.button2.Text = "前一条记录";
            this.button2.Click  = new System.EventHandler(this.button2_Click);
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(368, 64);
            this.button3.Name = "button3";
            this.button3.TabIndex = 3;
            this.button3.Text = "后一条记录";
            this.button3.Click  = new System.EventHandler(this.button3_Click);
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(368, 88);
            this.button4.Name = "button4";
            this.button4.TabIndex = 4;
            this.button4.Text = "末一条记录";
            this.button4.Click  = new System.EventHandler(this.button4_Click);
            //
            // button5
            //
            this.button5.Location = new System.Drawing.Point(368, 112);
            this.button5.Name = "button5";
            this.button5.TabIndex = 5;
            this.button5.Text = "新建记录";
            this.button5.Click  = new System.EventHandler(this.button5_Click);
            //
            // button6
            //
            this.button6.Location = new System.Drawing.Point(368, 136);
            this.button6.Name = "button6";
            this.button6.TabIndex = 6;
            this.button6.Text = "增加记录";
            this.button6.Click  = new System.EventHandler(this.button6_Click);
            //
            // button7
            //
            this.button7.Location = new System.Drawing.Point(368, 160);
            this.button7.Name = "button7";
            this.button7.TabIndex = 7;
            this.button7.Text = "修改记录";
            this.button7.Click  = new System.EventHandler(this.button7_Click);
            //
            // button8
            //
            this.button8.Location = new System.Drawing.Point(368, 184);
            this.button8.Name = "button8";
            this.button8.TabIndex = 2;
            this.button8.Text = "删除记录";
            this.button8.Click  = new System.EventHandler(this.button8_Click);
            //
            // button9
            //
            this.button9.Location = new System.Drawing.Point(368, 208);
            this.button9.Name = "button9";
            this.button9.TabIndex = 8;
            this.button9.Text = "关闭程序";
            this.button9.Click  = new System.EventHandler(this.button9_Click);
            //
            // oleDbDataAdapter1
            //
            this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
            this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
            this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
            this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                                                                                                        new System.Data.Common.DataTableMapping("Table", "客户", new System.Data.Common.DataColumnMapping[] {
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("城市", "城市"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("传真", "传真"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("地区", "地区"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("地址", "地址"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("电话", "电话"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("公司名称", "公司名称"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("国家", "国家"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("客户ID", "客户ID"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("联系人头衔", "联系人头衔"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("联系人姓名", "联系人姓名"),
                                                                                                                                                                                                              new System.Data.Common.DataColumnMapping("邮政编码", "邮政编码")})});
            this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
            //
            // oleDbDeleteCommand1
            //
            this.oleDbDeleteCommand1.CommandText = @"DELETE FROM 客户 WHERE (客户ID = ?) AND (传真 = ? OR ? IS NULL AND 传真 IS NULL) AND (公司名称 = ?) AND (国家 = ? OR ? IS NULL AND 国家 IS NULL) AND (地区 = ? OR ? IS NULL AND 地区 IS NULL) AND (地址 = ? OR ? IS NULL AND 地址 IS NULL) AND (城市 = ? OR ? IS NULL AND 城市 IS NULL) AND (电话 = ? OR ? IS NULL AND 电话 IS NULL) AND (联系人头衔 = ? OR ? IS NULL AND 联系人头衔 IS NULL) AND (联系人姓名 = ? OR ? IS NULL AND 联系人姓名 IS NULL) AND (邮政编码 = ? OR ? IS NULL AND 邮政编码 IS NULL)";
            this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_客户ID", System.Data.OleDb.OleDbType.VarWChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "客户ID", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_传真", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "传真", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_传真1", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "传真", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_公司名称", System.Data.OleDb.OleDbType.VarWChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "公司名称", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_国家", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "国家", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_国家1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "国家", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地区", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地区", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地区1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地区", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地址", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地址", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地址1", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地址", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_城市", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "城市", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_城市1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "城市", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_电话", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "电话", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_电话1", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "电话", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人头衔", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人头衔", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人头衔1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人头衔", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人姓名", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人姓名", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人姓名1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人姓名", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_邮政编码", System.Data.OleDb.OleDbType.VarWChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "邮政编码", System.Data.DataRowVersion.Original, null));
            this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_邮政编码1", System.Data.OleDb.OleDbType.VarWChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "邮政编码", System.Data.DataRowVersion.Original, null));
            //
            // oleDbConnection1
            //
            this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""Northwind.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False";
            //
            // oleDbInsertCommand1
            //
            this.oleDbInsertCommand1.CommandText = "INSERT INTO 客户(城市, 传真, 地区, 地址, 电话, 公司名称, 国家, 客户ID, 联系人头衔, 联系人姓名, 邮政编码) VALUES (?," 
                " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("城市", System.Data.OleDb.OleDbType.VarWChar, 15, "城市"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("传真", System.Data.OleDb.OleDbType.VarWChar, 24, "传真"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("地区", System.Data.OleDb.OleDbType.VarWChar, 15, "地区"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("地址", System.Data.OleDb.OleDbType.VarWChar, 60, "地址"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("电话", System.Data.OleDb.OleDbType.VarWChar, 24, "电话"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("公司名称", System.Data.OleDb.OleDbType.VarWChar, 40, "公司名称"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("国家", System.Data.OleDb.OleDbType.VarWChar, 15, "国家"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("客户ID", System.Data.OleDb.OleDbType.VarWChar, 5, "客户ID"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("联系人头衔", System.Data.OleDb.OleDbType.VarWChar, 30, "联系人头衔"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("联系人姓名", System.Data.OleDb.OleDbType.VarWChar, 30, "联系人姓名"));
            this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("邮政编码", System.Data.OleDb.OleDbType.VarWChar, 10, "邮政编码"));
            //
            // oleDbSelectCommand1
            //
            this.oleDbSelectCommand1.CommandText = "SELECT 城市, 传真, 地区, 地址, 电话, 公司名称, 国家, 客户ID, 联系人头衔, 联系人姓名, 邮政编码 FROM 客户";
            this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
            //
            // oleDbUpdateCommand1
            //
            this.oleDbUpdateCommand1.CommandText = @"UPDATE 客户 SET 城市 = ?, 传真 = ?, 地区 = ?, 地址 = ?, 电话 = ?, 公司名称 = ?, 国家 = ?, 客户ID = ?, 联系人头衔 = ?, 联系人姓名 = ?, 邮政编码 = ? WHERE (客户ID = ?) AND (传真 = ? OR ? IS NULL AND 传真 IS NULL) AND (公司名称 = ?) AND (国家 = ? OR ? IS NULL AND 国家 IS NULL) AND (地区 = ? OR ? IS NULL AND 地区 IS NULL) AND (地址 = ? OR ? IS NULL AND 地址 IS NULL) AND (城市 = ? OR ? IS NULL AND 城市 IS NULL) AND (电话 = ? OR ? IS NULL AND 电话 IS NULL) AND (联系人头衔 = ? OR ? IS NULL AND 联系人头衔 IS NULL) AND (联系人姓名 = ? OR ? IS NULL AND 联系人姓名 IS NULL) AND (邮政编码 = ? OR ? IS NULL AND 邮政编码 IS NULL)";
            this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("城市", System.Data.OleDb.OleDbType.VarWChar, 15, "城市"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("传真", System.Data.OleDb.OleDbType.VarWChar, 24, "传真"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("地区", System.Data.OleDb.OleDbType.VarWChar, 15, "地区"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("地址", System.Data.OleDb.OleDbType.VarWChar, 60, "地址"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("电话", System.Data.OleDb.OleDbType.VarWChar, 24, "电话"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("公司名称", System.Data.OleDb.OleDbType.VarWChar, 40, "公司名称"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("国家", System.Data.OleDb.OleDbType.VarWChar, 15, "国家"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("客户ID", System.Data.OleDb.OleDbType.VarWChar, 5, "客户ID"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("联系人头衔", System.Data.OleDb.OleDbType.VarWChar, 30, "联系人头衔"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("联系人姓名", System.Data.OleDb.OleDbType.VarWChar, 30, "联系人姓名"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("邮政编码", System.Data.OleDb.OleDbType.VarWChar, 10, "邮政编码"));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_客户ID", System.Data.OleDb.OleDbType.VarWChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "客户ID", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_传真", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "传真", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_传真1", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "传真", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_公司名称", System.Data.OleDb.OleDbType.VarWChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "公司名称", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_国家", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "国家", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_国家1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "国家", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地区", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地区", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地区1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地区", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地址", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地址", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_地址1", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "地址", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_城市", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "城市", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_城市1", System.Data.OleDb.OleDbType.VarWChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "城市", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_电话", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "电话", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_电话1", System.Data.OleDb.OleDbType.VarWChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "电话", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人头衔", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人头衔", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人头衔1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人头衔", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人姓名", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人姓名", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_联系人姓名1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "联系人姓名", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_邮政编码", System.Data.OleDb.OleDbType.VarWChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "邮政编码", System.Data.DataRowVersion.Original, null));
            this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_邮政编码1", System.Data.OleDb.OleDbType.VarWChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "邮政编码", System.Data.DataRowVersion.Original, null));
            //
            // dataSet1
            //
            this.dataSet1.DataSetName = "NewDataSet";
            this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(448, 238);
            this.Controls.Add(this.button9);
            this.Controls.Add(this.button7);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.button8);
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "演示读写ACCESS数据库";
            this.Load  = new System.EventHandler(this.Form1_Load);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
            this.ResumeLayout(false);
 
        }
        #endregion
 
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
 
        private void Form1_Load(object sender, System.EventArgs e)
        {//初始化数据集
            try
            {
                this.oleDbDataAdapter1.Fill(this.dataSet1,"客户");
                this.textBox1.DataBindings.Add("Text",this.dataSet1,"客户.客户ID");
                this.textBox2.DataBindings.Add("Text",this.dataSet1,"客户.公司名称");
                this.textBox3.DataBindings.Add("Text",this.dataSet1,"客户.联系人姓名");
                this.textBox4.DataBindings.Add("Text",this.dataSet1,"客户.联系人头衔");
                this.textBox5.DataBindings.Add("Text",this.dataSet1,"客户.地址");
                this.textBox6.DataBindings.Add("Text",this.dataSet1,"客户.城市");
                this.textBox7.DataBindings.Add("Text",this.dataSet1,"客户.地区");
                this.textBox8.DataBindings.Add("Text",this.dataSet1,"客户.邮政编码");
                this.textBox9.DataBindings.Add("Text",this.dataSet1,"客户.国家");
                this.textBox10.DataBindings.Add("Text",this.dataSet1,"客户.电话");
                this.textBox11.DataBindings.Add("Text",this.dataSet1,"客户.传真");
                this.MyBind=this.BindingContext[this.dataSet1,"客户"];
            }
            catch(Exception Err)
            {
                MessageBox.Show("打开数据库表错误:" Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }  
        }
        private void button1_Click(object sender, System.EventArgs e)
        {//第一条记录
            this.MyBind.Position=0;    
        }
        private void button2_Click(object sender, System.EventArgs e)
        {//前一条记录
            if(this.MyBind.Position==0)
            {
                MessageBox.Show("已经是第一条记录","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            else
                this.MyBind.Position--;
        }
 
        private void button3_Click(object sender, System.EventArgs e)
        {//后一条记录
            if(this.MyBind.Position==this.MyBind.Count-1)
            {
                MessageBox.Show("已经是末一条记录","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            else
                this.MyBind.Position  ;
         
        }
 
        private void button4_Click(object sender, System.EventArgs e)
        {//末一条记录
            this.MyBind.Position=this.MyBind.Count-1;
        }
 
        private void button5_Click(object sender, System.EventArgs e)
        {//新建记录
            this.textBox1.Text="";
            this.textBox2.Text="";
            this.textBox3.Text="";
            this.textBox4.Text="";
            this.textBox5.Text="";
            this.textBox6.Text="";
            this.textBox7.Text="";
            this.textBox8.Text="";
            this.textBox9.Text="";
            this.textBox10.Text="";
            this.textBox11.Text="";        
        }
 
        private void button6_Click(object sender, System.EventArgs e)
        {//增加记录
            if(this.textBox1.Text.Length<1|this.textBox2.Text.Length<1|this.textBox3.Text.Length<1|
                this.textBox4.Text.Length<1|this.textBox5.Text.Length<1|this.textBox6.Text.Length<1|
                this.textBox7.Text.Length<1|this.textBox8.Text.Length<1|this.textBox9.Text.Length<1|
                this.textBox10.Text.Length<1|this.textBox11.Text.Length<1)
            {
                MessageBox.Show("客户所有信息必须填写!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            try
            {
                string StrSQL="INSERT INTO 客户(客户ID,公司名称,联系人姓名,联系人头衔,地址,城市,地区,邮政编码,国家,电话,传真)VALUES('";
                StrSQL =this.textBox1.Text "','";
                StrSQL =this.textBox2.Text "','";
                StrSQL =this.textBox3.Text "','";
                StrSQL =this.textBox4.Text "','";
                StrSQL =this.textBox5.Text "','";
                StrSQL =this.textBox6.Text "','";
                StrSQL =this.textBox7.Text "','";
                StrSQL =this.textBox8.Text "','";
                StrSQL =this.textBox9.Text "','";
                StrSQL =this.textBox10.Text "','";
                StrSQL =this.textBox11.Text "')";              
                this.oleDbCommand1.CommandText=StrSQL;
                this.oleDbCommand1.Connection=this.oleDbConnection1;
                //打开数据库连接
                this.oleDbConnection1.Open();
                //执行SQL命令
                this.oleDbCommand1.ExecuteNonQuery();
                //关闭连接
                this.oleDbConnection1.Close();
                //更新数据集
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].BeginEdit();
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].EndEdit();               
                this.dataSet1.AcceptChanges();
                MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch(Exception Err)
            {
                MessageBox.Show("增加数据集记录操作失败:" Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                //如果打开了连接,则关闭它
                if(this.oleDbConnection1.State==ConnectionState.Open)
                {
                    this.oleDbConnection1.Close();
                }
            }      
        }
 
        private void button7_Click(object sender, System.EventArgs e)
        {//修改记录
            if(this.textBox1.Text.Length<1)
            {
                MessageBox.Show("客户ID必须填写!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            try
            {
                string StrSQL="UPDATE 客户 SET";
                StrSQL =" 公司名称='" this.textBox2.Text;
                StrSQL ="', 联系人姓名='" this.textBox3.Text;
                StrSQL ="', 联系人头衔='" this.textBox4.Text;
                StrSQL ="', 地址='" this.textBox5.Text;
                StrSQL ="', 城市='" this.textBox6.Text;
                StrSQL ="', 地区='" this.textBox7.Text;
                StrSQL ="', 邮政编码='" this.textBox8.Text;
                StrSQL ="', 国家='" this.textBox9.Text;
                StrSQL ="', 电话='" this.textBox10.Text;
                StrSQL ="', 传真='" this.textBox11.Text "' WHERE  客户ID='" this.textBox1.Text "'";
                this.oleDbCommand1.CommandText=StrSQL;
                this.oleDbCommand1.Connection=this.oleDbConnection1;
                //打开数据库连接
                this.oleDbConnection1.Open();
                //执行SQL命令
                this.oleDbCommand1.ExecuteNonQuery();
                //关闭连接
                this.oleDbConnection1.Close();
                //更新数据集
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].BeginEdit();
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].EndEdit();               
                this.dataSet1.AcceptChanges();
                this.oleDbDataAdapter1.Fill(this.dataSet1,"客户");
                MessageBox.Show("修改数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch(Exception Err)
            {
                MessageBox.Show("修改数据集记录操作失败:" Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                //如果打开了连接,则关闭它
                if(this.oleDbConnection1.State==ConnectionState.Open)
                {
                    this.oleDbConnection1.Close();
                }
            }              
        }
 
        private void button8_Click(object sender, System.EventArgs e)
        {//删除记录
            try
            {
                string StrSQL="DELETE FROM  客户 WHERE ";
                StrSQL =" 客户ID='" this.textBox1.Text "'";              
                this.oleDbCommand1.CommandText=StrSQL;
                this.oleDbCommand1.Connection=this.oleDbConnection1;
                //打开数据库连接
                this.oleDbConnection1.Open();
                //执行SQL命令
                this.oleDbCommand1.ExecuteNonQuery();
                //关闭连接
                this.oleDbConnection1.Close();
                //更新数据集
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].BeginEdit();
                this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].EndEdit();               
                this.dataSet1.AcceptChanges();
                this.oleDbDataAdapter1.Fill(this.dataSet1,"客户");
                this.MyBind.Position=0;
                MessageBox.Show("删除数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch(Exception Err)
            {
                MessageBox.Show("删除数据集记录操作失败:" Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                //如果打开了连接,则关闭它
                if(this.oleDbConnection1.State==ConnectionState.Open)
                {
                    this.oleDbConnection1.Close();
                }
            }                      
        }
 
        private void button9_Click(object sender, System.EventArgs e)
        {//关闭程序
            //如果打开了连接,则关闭它
            if(this.oleDbConnection1.State==ConnectionState.Open)
            {
                this.oleDbConnection1.Close();
            }
            this.Close();      
        }
 
    }
}


实例下载地址

C# 读写access数据库

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 xiaoouqiyi 发表于: 2017-09-01 21:33 15
打不开

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警