日期:2014-05-18 浏览次数:20763 次
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.Odbc; namespace WinForm { public partial class frmReport : Form { public frmReport() { InitializeComponent(); } private void frmReport_Load(object sender, EventArgs e) { dataGridView1.DataSource = AddData(); } private DataTable AddData() { string strsql = "select * from navverchgrec"; OdbcConnection conn = new OdbcConnection("Dsn=PostgreSQLTighten;"); DataSet ds = new DataSet(); try { conn.Open(); OdbcDataAdapter dat = new OdbcDataAdapter(strsql, conn); dat.Fill(ds); return ds.Tables[0]; } catch (Exception) { return null; } finally { conn.Close(); dataGridView1.Columns["aaa"].Visible = false; } } private void button1_Click(object sender, EventArgs e) { dataGridView1.Columns["aaa"].Visible = !dataGridView1.Columns["aaa"].Visible; dataGridView1.Columns["versionname"].Visible = !dataGridView1.Columns["versionname"].Visible; } } }