有疑问
来源:互联网 发布:c语言buffer 编辑:程序博客网 时间:2024/05/16 18:15
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace _20160514_DataGridview{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: 这行代码将数据加载到表“maibo0415DataSet.xx_bumen”中。您可以根据需要移动或删除它。 this.xx_bumenTableAdapter.Fill(this.maibo0415DataSet.xx_bumen); dataGridView2.DataSource = mydataSourse().Tables[0]; //table[0]? } DataSet mydataSourse() { string mycstr = "server=.;user=sa;pwd=sa;database=maibo0415"; SqlConnection myconn = new SqlConnection(mycstr); string myselection = "select *from xx_yuangong"; DataSet mydataset = new DataSet(); try { myconn.Open(); SqlDataAdapter mydataapdter = new SqlDataAdapter(myselection, myconn); mydataapdter.Fill(mydataset,"mytable"); this.dataGridView1.AutoGenerateColumns = true; //自动生成列 // this.dataGridView1.DataSource=my this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter; } catch (Exception ex){ MessageBox.Show(ex.Message); } finally { myconn.Close(); } return mydataset; //return } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int row = dataGridView1.CurrentCell.RowIndex + 1; int collm = e.ColumnIndex + 1; //e string myvalue = dataGridView1.CurrentCell.Value.ToString(); MessageBox.Show(row.ToString()+collm.ToString()+myvalue.ToString()); } private void button1_Click(object sender, EventArgs e) { dataGridView1.Columns[4].Visible = false; } private void button2_Click(object sender, EventArgs e) { dataGridView1.Columns[4].Visible =true; } private void button3_Click(object sender, EventArgs e) { dataGridView1.Rows[5].Visible = false; } public int rowIdex =0; private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { this.dataGridView1.Rows[e.RowIndex].Selected = true; //可被选择 rowIdex = e.RowIndex; this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1]; //清除选择? //this.contextMenuStrip1.Show(this.dataGridView1,e.Location); this.contextMenuStrip1.Show(Cursor.Position); //鼠标 } } private void contextMenuStrip1_Click(object sender, EventArgs e) { if (!this.dataGridView1.Rows[this.rowIdex].IsNewRow) this.dataGridView1.Rows.RemoveAt(rowIdex); } private void button4_Click(object sender, EventArgs e) { dataGridView1.Sort(dataGridView1.Columns[3], ListSortDirection.Ascending); } private void button5_Click(object sender, EventArgs e) { DataView mydv = new DataView(this.maibo0415DataSet.xx_bumen, "部门名称='人事部'","部门人数 asc",DataViewRowState.CurrentRows); // mydv = maibo0415DataSet.xx_bumen,"部门名称='人事部'" dataGridView1.DataSource = mydv; } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { string mystr0 = "server =.; user = sa; pwd = sa; database = maibo0415"; SqlConnection myconn = new SqlConnection(mystr0); try { string mystr1 = dataGridView1.Columns[e.ColumnIndex].HeaderText + "=" + "'" + dataGridView1.CurrentCell.Value.ToString() + "'"; //列名 string mystr2 = "'" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() + "'"; myconn.Open(); string myupdata = "update xx_bumen set " + mystr1 + "where 部门名称=" + mystr2; SqlCommand mycom = new SqlCommand(myupdata,myconn); mycom.ExecuteNonQuery(); mydataSourse(); } catch (Exception ex) { MessageBox.Show(ex.Message);} finally { myconn.Close(); } } }}
0 0
- 有疑问
- 突然有个疑问。。。
- 有好多疑问啊
- 有个疑问~~~
- 有疑问的题
- 有疑问的题目
- 新手哦有疑问啊
- 栈 括号匹配 有疑问
- c++嵌套类--有疑问
- 分糖果(有疑问)
- 比较器的用法(有疑问)
- USACO Fractions to Decimals,有重大疑问
- Essential c++ 第三章代码(有疑问)
- 关于冒泡法,我有几个疑问
- 0day汇编shellcode有基础疑问
- 最大子序列(有疑问)
- 虚继承类大小(内容有疑问?)
- call与apply(2) //有疑问
- ConvertFromAction
- C/C++对文件的读写
- 如何设置幻灯片自动播放
- ecshop邮件服务器设置注意事项
- ConvertToAction
- 有疑问
- ZOJ 2419-- Triangle-凸包+旋转卡壳求最大面积三角形(计算几何)
- Python实战_2_第一周_第三节课程:真实世界中的网页解析
- Android FlexboxLayout基本用法
- SampleAction
- LinuxC编程一站式学习(C语言本质)
- 国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard
- 最大熵模型
- 单例模式