数据库用的是本地服务器(MySql):
设定全局变量:
MySqlConnection conn;
MySqlDataAdapter adapter;
MySqlTransaction trans;
1. // 数据库联接
private System.Data.DataTable dbconn(string strSql)
{
string strconn = "host=localhost;database=test;user id=root;password=";
conn = new MySqlConnection();
conn.ConnectionString = strconn;
conn.Open();
this.adapter = new MySqlDataAdapter(strSql, conn);
System.Data.DataTable dtSelect = new System.Data.DataTable();
int rnt=this.adapter.Fill(dtSelect);
conn.Close();
return dtSelect;
}
2. //设定 DataGridView 的样式
private void setDgStyle()
{
this.dgselect.Columns.Clear();
DataGridViewCheckBoxColumn colDel = new DataGridViewCheckBoxColumn();
colDel.DataPropertyName = "Del";
colDel.Name = "Del";
colDel.Selected = false;
colDel.FalseValue = "0";
colDel.TrueValue = "1";
colDel.Width = 40;
colDel.SortMode = DataGridViewColumnSortMode.NotSortable;
colDel.HeaderText = "删除";
colDel.HeaderCell.Style.Alignment =
DataGridViewContentAlignment.MiddleCenter;
colDel.DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleCenter;
this.dgselect.Columns.Insert(0, colDel);
DataGridViewTextBoxColumn colID = new DataGridViewTextBoxColumn();
colID.DataPropertyName = "ProductsSpecID";
colID.Name = "ProductsSpecID";
colID.HeaderCell.Style.Alignment =
DataGridViewContentAlignment.MiddleCenter;
评论16
最新资源