using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DataBase;namespace aa
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
       
        public void InsertData(string name, string value)
        {
            SqlParameter[] parModule = new SqlParameter[3];            parModule[0] = new SqlParameter("@Year", SqlDbType.VarChar, 60);            parModule[0].Value = this.cbYear.Text.ToString().Trim();            parModule[1] = new SqlParameter("@Name", SqlDbType.VarChar, 60);            parModule[1].Value = name;            parModule[2] = new SqlParameter("@Value", SqlDbType.VarChar, 50);            parModule[2].Value = Convert.ToString(value);
            string addModule = "insert into InMoney Values (@Year,@Name,@Value)";
            Connection.ExecuteScalar(addModule, parModule);
            
        }
        public bool CheckValue()
        {
          
            SqlParameter[] parYear = new SqlParameter[1];            parYear[0] = new SqlParameter("@Year", SqlDbType.VarChar, 60);            parYear[0].Value = this.cbYear.Text.ToString().Trim();            string selectData = "select * from InMoney where In_Year = @Year";            int i = Connection.ExecuteCount(selectData, parYear);            if (i > 0)
            {
                MessageBox.Show(this.cbYear.Text + "数据已录入!");                return false;
            }           
            return true;
        }        private void button1_Click(object sender, EventArgs e)
        {
           
            if (this.CheckValue())
            {
               InsertData(this.label1.Text.ToString().Trim(), this.textBox1.Text.ToString().Trim());
               InsertData(this.label2.Text.ToString().Trim(), this.textBox2.Text.ToString().Trim());
               InsertData(this.label3.Text.ToString().Trim(), this.cbYear.Text.ToString().Trim());
              MessageBox.Show("数据全部录入完毕!");
              this.textBox1.Text = string.Empty;
              this.textBox2.Text = string.Empty;
              this.cbYear.Text = string.Empty;
            }
            
        }
public static object ExecuteScalar(string sqlString, SqlParameter[] cmdParms)
        {
            object result = null;
            SqlConnection conn = GetConnection();
            SqlCommand cmd = new SqlCommand(sqlString, conn);
            cmd.CommandType = CommandType.Text;            for (int iCount = 0; iCount < cmdParms.Length; iCount++)
            {
                cmd.Parameters.Add(cmdParms[iCount]);
            }            try
            {
                result = cmd.ExecuteScalar();
            }
            catch
            {
                conn.Close();
                throw;
            }
            return result;
        }显示录入成功,但数据无法写入数据库中
曾经录入的数据下次再录入的时候却显示此数已录入
这是为什么?