通过编写应用程序实现删除,添加,修改的功能。但是我用vs总是出现错误。不知道为什么。代码如下: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;namespace cj1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection cn1 = new SqlConnection();
            cn1.ConnectionString = "server=(local);database=cj;trusted_connection=yes";
            SqlCommand cmd1 = new SqlCommand();
            cmd1.Connection = cn1;
            cmd1.CommandText = "update cjb set cj='90' where xh='1'";
            cn1.Open();
            cmd1.ExecuteNonQuery();
            MessageBox.Show("修改成功.");
        }        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection cn1 = new SqlConnection();
            cn1.ConnectionString = "server=(local);database=cj;trusted_connection=yes";
            SqlCommand cmd1 = new SqlCommand();
            cmd1.Connection = cn1;
            cmd1.CommandText = "insert into cjb (xh,cj) values('2','80')";
            cn1.Open();
            cmd1.ExecuteNonQuery();
            MessageBox.Show("添加成功.");
        }        private void button3_Click(object sender, EventArgs e)
        {
            SqlConnection cn1 = new SqlConnection();
            cn1.ConnectionString = "server=(local);database=cj;trusted_connection=yes";
            SqlCommand cmd1 = new SqlCommand();
            cmd1.Connection = cn1;
            cmd1.CommandText = "delete from cjb where cj like '80'";
            cn1.Open();
            cmd1.ExecuteNonQuery();
            MessageBox.Show("删除成功.");
        }
    }
}
请大家试试看。
请大家告诉我原因。
谢谢。
真的谢谢

解决方案 »

  1.   

    估计是连接字符串的问题吧,换成
    Server=(local);database=cj;Integrated   Security=SSPI; 
    试试看
      

  2.   

    这代码写的...别说OO了OP都不是...让我想起了10年前的Foxbase...
      

  3.   

    你的命名太不规范了,数据库登录验证方式选择windows身份验证,Integrated Security=true;也可以解决!
      

  4.   

    不要说人家,自己学的时候也一样!!
    谁能一出生就会走?一口吃成胖子???不都需要个过程么?这时,最应该说鼓励的话!!LZ,我鼓励你!
    Fighting!!!