本文介绍了没有得到插入更新删除任何人告诉我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
string strCon = "Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True";
string strSQL;
SqlConnection conn;
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strSQL = "select * from gridview";
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = bindingSource1;
}
private void btninsert_Click(object sender, EventArgs e)
{
strSQL = "insert into gridview values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
conn = new SqlConnection(strCon);
cmd = new SqlCommand(strSQL, conn);
conn.Open();
cmd.ExecuteNonQuery();
dataGridView1.DataSource = bindingSource1;
conn.Close();
}
private void btnupdate_Click(object sender, EventArgs e)
{
strSQL = "update gridview set ID='" + textBox1.Text + "',Name='" + textBox2.Text + "',Address='" + textBox3.Text + "'";
conn = new SqlConnection(strCon);
cmd = new SqlCommand(strSQL, conn);
conn.Open();
cmd.ExecuteNonQuery();
dataGridView1.DataSource = bindingSource1;
}
private void btndelete_Click(object sender, EventArgs e)
{
strSQL = "delete from gridview";
conn = new SqlConnection(strCon);
cmd = new SqlCommand(strSQL, conn);
conn.Open();
cmd.ExecuteNonQuery();
dataGridView1.DataSource = bindingSource1;
}
}
}
推荐答案
这篇关于没有得到插入更新删除任何人告诉我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!