通过编写应用程序实现删除,添加,修改的功能。但是我用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("删除成功.");
}
}
}
请大家试试看。
请大家告诉我原因。
谢谢。
真的谢谢
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("删除成功.");
}
}
}
请大家试试看。
请大家告诉我原因。
谢谢。
真的谢谢
Server=(local);database=cj;Integrated Security=SSPI;
试试看
谁能一出生就会走?一口吃成胖子???不都需要个过程么?这时,最应该说鼓励的话!!LZ,我鼓励你!
Fighting!!!