close

The CREATE DATABASE statement is used to create a database.

語法: CREATE DATABASE dbname;

範例: CREATE DATABASE car;

 

The CREATE TABLE statement is used to create a table in a database.

   1: CREATE TABLE table_name
   2: (
   3: column_name1 data_type(size),
   4: column_name2 data_type(size),
   5: column_name3 data_type(size),
   6: ....
   7: );

image

   1: USE [car]
   2: GO
   3:  
   4: SET ANSI_NULLS ON
   5: GO
   6:  
   7: SET QUOTED_IDENTIFIER ON
   8: GO
   9:  
  10: SET ANSI_PADDING ON
  11: GO
  12:  
  13: CREATE TABLE [dbo].[Photo](
  14:     [Id] [int] IDENTITY(1,1) NOT NULL,
  15:     [CameraId] [varchar](20) NOT NULL,
  16:     [CreateDate] [datetime] NOT NULL,
  17:     [CarId] [varchar](20) NOT NULL,
  18:     [Type] [varchar](1) NOT NULL,
  19:     [Src] [nvarchar](250) NOT NULL,
  20:  CONSTRAINT [PK_CarPhoto] PRIMARY KEY CLUSTERED 
  21: (
  22:     [Id] ASC
  23: )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  24: ) ON [PRIMARY]
  25:  
  26: GO
  27:  
  28: SET ANSI_PADDING OFF
  29: GO

image

寫入資料

 

image

下拉選單

image

   1: Dictionary<string, string> types = new Dictionary<string, string>();
   2: types.Add("", "全部");
   3: types.Add("0", "0.正常");
   4: types.Add("1", "1.遺失");
   5: comboType.DataSource = new BindingSource(types, null);
   6: comboType.DisplayMember = "Value";
   7: comboType.ValueMember = "Key";

Datagrid 插入一行checkbox

利用DataGridViewCheckBoxColumn建立 CheckBox 欄

   1: // 建立 CheckBox 欄
   2: DataGridViewCheckBoxColumn cbCol = new DataGridViewCheckBoxColumn();
   3: cbCol.Width = 50;   //設定寬度
   4: cbCol.HeaderText = " 全選";
   5: cbCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;   //置中
   6: dataGridView1.Columns.Insert(0, cbCol);

 

建立矩形,等下計算 CheckBox 嵌入 GridView 的位置

   1: // 建立矩形,等下計算 CheckBox 嵌入 GridView 的位置
   2: Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
   3: rect.X = rect.Location.X + rect.Width / 4 - 9;
   4: rect.Y = rect.Location.Y + (rect.Height / 2 - 9);
   5:  
   6: // 創建checkbox,設定在剛才矩形位置(rect)
   7: CheckBox cbHeader = new CheckBox();
   8: cbHeader.Name = "checkboxHeader";
   9: cbHeader.Size = new Size(18, 18);
  10: cbHeader.Location = rect.Location;

 

全選事件

   1: // 全選事件
   2: cbHeader.CheckedChanged += new EventHandler((object sender, EventArgs e) => {                             
   3:     foreach (DataGridViewRow dr in dataGridView1.Rows)
   4:         dr.Cells[0].Value = ((CheckBox)dataGridView1.Controls.Find("checkboxHeader", true)[0]).Checked;
   5: });
   6:  
   7: //將 CheckBox 加入到 dataGridView
   8: dataGridView1.Controls.Add(cbHeader);
   9: dataGridView1.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

image

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()