日期:2014-05-20  浏览次数:20795 次

我知道这个问题很低级,呵,但小弟是刚学
提交到数据库表为user,字段为name,age
数据库组件有oledbconnection1和oledbcommand1,oledbconnection1已连接好ACCESS数据库
错误提示:错误 1 “System.Data.OleDb.OleDbCommand”并不包含“commandText”的定义 F:\c#练习\lesson1\lesson1\Form1.cs

using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Data.OleDb;
using   System.Data.Common;
using   System.Windows.Forms;

namespace   lesson1
{
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();
                }

                private   void   button2_Click(object   sender,   EventArgs   e)
                {
                        this.Close();
                }

                private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        if   (textBox1.Text.Trim()   ==   " "   ||   textBox2.Text.Trim()   ==   " ")
                        {  
                                MessageBox.Show( "姓名和年龄都不能为空! ");
                                return;
                        }
                        OleDbCommand   cmd   =   new   OleDbCommand1( "select   *   from   user   where   name= ' "   +   textBox1.Text.Trim()   +   " ' ",   oleDbConnection1);
                        if   (null   !=   cmd.ExecuteScalar())
                                MessageBox.Show( "这人已经输入过啦 ");
                        else
                        {
                                string   sql   =   "insert   into   user   (name,age)   values   ( ' "   +   textBox1.Text.Trim()   +   " ', ' "   +   textBox2.Text.Trim()   +   " ') ";
                                cmd.commandText   =   sql;
                                cmd.ExecuteNonQuery();