コマンドのみで、コンボボックスのバリューメンバー、ディスプレイメンバーを表示するには?

解決


soushi  2004-12-13 10:23:05  No: 118238  IP: [192.*.*.*]

コンボボックスに、displaymemberと、valuememberがあるのは知っているんですが、プロパティではなく、自分でコマンド手打ちしてやりたいんです。

cmbSyozoku.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.ds, "社員IDマスター.所属ID"))
        cmbSyozoku.DisplayMember = "社員IDマスター.所属ID"
        cmbSyozoku.Text = "System.Data.DataViewManagerListItemTypeDescriptor"
        cmbSyozoku.ValueMember = "所属マスター.所属名"
現在のコマンドはこうなっています。dsっていうのはデータセットです。
どなたか、教えてください。

編集 削除
nanashi  2004-12-13 10:59:42  No: 118239  IP: [192.*.*.*]

> コンボボックスに、displaymemberと、valuememberがあるのは知っているんですが、
> プロパティではなく、自分でコマンド手打ちしてやりたいんです。

すみません、これの意味と意図が全く分かりません。

編集 削除
soushi  2004-12-13 11:16:34  No: 118240  IP: [192.*.*.*]

学校の課題で、作ってるんですが、VB.netとSQLサーバーを使って、ラベルとか以外はすべて手打ち入力で、作成しろって言う課題なんです。

プロパティつかってやるのは本にあるんですが、手打ちでやるのは書いてないんで、困っているんです。

編集 削除
soushi  2004-12-13 11:26:42  No: 118241  IP: [192.*.*.*]

表示と、格納はできたんですが、一度データを送信すると、その後、表示すらされなくなりました。

Public Class frmAdd
    Inherits System.Windows.Forms.Form
    Private ID As String
    Private scn As SqlClient.SqlConnection
    Private sda As SqlClient.SqlDataAdapter
    Private sdaSyozoku As SqlClient.SqlDataAdapter
    Private sdaYakusyoku As SqlClient.SqlDataAdapter
    Private scd As New SqlClient.SqlCommand
    Private ds As New Data.DataSet

    
#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    'Windows フォーム デザイナを使って変更してください。  
    ' コード エディタを使って変更しないでください。
    Friend WithEvents txtID As System.Windows.Forms.TextBox
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents txtBirthDay As System.Windows.Forms.TextBox
    Friend WithEvents txtEmail As System.Windows.Forms.TextBox
    Friend WithEvents txtPost As System.Windows.Forms.TextBox
    Friend WithEvents txtAddress As System.Windows.Forms.TextBox
    Friend WithEvents txtTel As System.Windows.Forms.TextBox
    Friend WithEvents txtKeitai As System.Windows.Forms.TextBox
    Friend WithEvents txtTansyuku As System.Windows.Forms.TextBox
    Friend WithEvents txtNaisen As System.Windows.Forms.TextBox
    Friend WithEvents txtNyuusya As System.Windows.Forms.TextBox
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnReset As System.Windows.Forms.Button
    Friend WithEvents lblID As System.Windows.Forms.Label
    Friend WithEvents lblName As System.Windows.Forms.Label
    Friend WithEvents lblKana As System.Windows.Forms.Label
    Friend WithEvents lblSex As System.Windows.Forms.Label
    Friend WithEvents lblBirthDay As System.Windows.Forms.Label
    Friend WithEvents lblSyozoku As System.Windows.Forms.Label
    Friend WithEvents lblYakusyoku As System.Windows.Forms.Label
    Friend WithEvents lblTel As System.Windows.Forms.Label
    Friend WithEvents lblEMail As System.Windows.Forms.Label
    Friend WithEvents lblPost As System.Windows.Forms.Label
    Friend WithEvents lblAddress As System.Windows.Forms.Label
    Friend WithEvents lblKeitai As System.Windows.Forms.Label
    Friend WithEvents lblTansyuku As System.Windows.Forms.Label
    Friend WithEvents lblNaisen As System.Windows.Forms.Label
    Friend WithEvents lblNyuusya As System.Windows.Forms.Label
    Friend WithEvents lblBlood As System.Windows.Forms.Label
    Friend WithEvents txtKana As System.Windows.Forms.TextBox
    Friend WithEvents cmbSex As System.Windows.Forms.ComboBox
    Friend WithEvents cmbBlood As System.Windows.Forms.ComboBox
    Friend WithEvents cmbSyozoku As System.Windows.Forms.ComboBox
    Friend WithEvents cmbYakusyoku As System.Windows.Forms.ComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lblID = New System.Windows.Forms.Label
        Me.lblName = New System.Windows.Forms.Label
        Me.lblKana = New System.Windows.Forms.Label
        Me.lblSex = New System.Windows.Forms.Label
        Me.lblBirthDay = New System.Windows.Forms.Label
        Me.lblSyozoku = New System.Windows.Forms.Label
        Me.lblYakusyoku = New System.Windows.Forms.Label
        Me.lblTel = New System.Windows.Forms.Label
        Me.lblEMail = New System.Windows.Forms.Label
        Me.lblPost = New System.Windows.Forms.Label
        Me.lblAddress = New System.Windows.Forms.Label
        Me.lblKeitai = New System.Windows.Forms.Label
        Me.lblTansyuku = New System.Windows.Forms.Label
        Me.lblNaisen = New System.Windows.Forms.Label
        Me.lblNyuusya = New System.Windows.Forms.Label
        Me.lblBlood = New System.Windows.Forms.Label
        Me.txtID = New System.Windows.Forms.TextBox
        Me.txtName = New System.Windows.Forms.TextBox
        Me.txtKana = New System.Windows.Forms.TextBox
        Me.txtBirthDay = New System.Windows.Forms.TextBox
        Me.txtEmail = New System.Windows.Forms.TextBox
        Me.txtPost = New System.Windows.Forms.TextBox
        Me.txtAddress = New System.Windows.Forms.TextBox
        Me.txtTel = New System.Windows.Forms.TextBox
        Me.txtKeitai = New System.Windows.Forms.TextBox
        Me.txtTansyuku = New System.Windows.Forms.TextBox
        Me.txtNaisen = New System.Windows.Forms.TextBox
        Me.txtNyuusya = New System.Windows.Forms.TextBox
        Me.btnSave = New System.Windows.Forms.Button
        Me.btnReset = New System.Windows.Forms.Button
        Me.cmbSex = New System.Windows.Forms.ComboBox
        Me.cmbBlood = New System.Windows.Forms.ComboBox
        Me.cmbSyozoku = New System.Windows.Forms.ComboBox
        Me.cmbYakusyoku = New System.Windows.Forms.ComboBox
        Me.SuspendLayout()
        '
        'lblID
        '
        Me.lblID.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblID.Location = New System.Drawing.Point(8, 8)
        Me.lblID.Name = "lblID"
        Me.lblID.Size = New System.Drawing.Size(128, 24)
        Me.lblID.TabIndex = 0
        Me.lblID.Text = "社員ID"
        Me.lblID.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblName
        '
        Me.lblName.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblName.Location = New System.Drawing.Point(8, 40)
        Me.lblName.Name = "lblName"
        Me.lblName.Size = New System.Drawing.Size(128, 24)
        Me.lblName.TabIndex = 1
        Me.lblName.Text = "氏名"
        Me.lblName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblKana
        '
        Me.lblKana.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblKana.Location = New System.Drawing.Point(8, 72)
        Me.lblKana.Name = "lblKana"
        Me.lblKana.Size = New System.Drawing.Size(128, 24)
        Me.lblKana.TabIndex = 2
        Me.lblKana.Text = "ふりがな"
        Me.lblKana.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblSex
        '
        Me.lblSex.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblSex.Location = New System.Drawing.Point(8, 104)
        Me.lblSex.Name = "lblSex"
        Me.lblSex.Size = New System.Drawing.Size(128, 24)
        Me.lblSex.TabIndex = 3
        Me.lblSex.Text = "性別"
        Me.lblSex.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblBirthDay
        '
        Me.lblBirthDay.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblBirthDay.Location = New System.Drawing.Point(8, 168)
        Me.lblBirthDay.Name = "lblBirthDay"
        Me.lblBirthDay.Size = New System.Drawing.Size(128, 24)
        Me.lblBirthDay.TabIndex = 4
        Me.lblBirthDay.Text = "生年月日"
        Me.lblBirthDay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblSyozoku
        '
        Me.lblSyozoku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblSyozoku.Location = New System.Drawing.Point(8, 200)
        Me.lblSyozoku.Name = "lblSyozoku"
        Me.lblSyozoku.Size = New System.Drawing.Size(128, 24)
        Me.lblSyozoku.TabIndex = 5
        Me.lblSyozoku.Text = "所属名"
        Me.lblSyozoku.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblYakusyoku
        '
        Me.lblYakusyoku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblYakusyoku.Location = New System.Drawing.Point(8, 232)
        Me.lblYakusyoku.Name = "lblYakusyoku"
        Me.lblYakusyoku.Size = New System.Drawing.Size(128, 24)
        Me.lblYakusyoku.TabIndex = 6
        Me.lblYakusyoku.Text = "役職"
        Me.lblYakusyoku.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblTel
        '
        Me.lblTel.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblTel.Location = New System.Drawing.Point(8, 360)
        Me.lblTel.Name = "lblTel"
        Me.lblTel.Size = New System.Drawing.Size(128, 24)
        Me.lblTel.TabIndex = 7
        Me.lblTel.Text = "自宅電話番号"
        Me.lblTel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblEMail
        '
        Me.lblEMail.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblEMail.Location = New System.Drawing.Point(8, 264)
        Me.lblEMail.Name = "lblEMail"
        Me.lblEMail.Size = New System.Drawing.Size(128, 24)
        Me.lblEMail.TabIndex = 7
        Me.lblEMail.Text = "電子メールアドレス"
        Me.lblEMail.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblPost
        '
        Me.lblPost.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblPost.Location = New System.Drawing.Point(8, 296)
        Me.lblPost.Name = "lblPost"
        Me.lblPost.Size = New System.Drawing.Size(128, 24)
        Me.lblPost.TabIndex = 8
        Me.lblPost.Text = "郵便番号"
        Me.lblPost.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblAddress
        '
        Me.lblAddress.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblAddress.Location = New System.Drawing.Point(8, 328)
        Me.lblAddress.Name = "lblAddress"
        Me.lblAddress.Size = New System.Drawing.Size(128, 24)
        Me.lblAddress.TabIndex = 9
        Me.lblAddress.Text = "住所"
        Me.lblAddress.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblKeitai
        '
        Me.lblKeitai.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblKeitai.Location = New System.Drawing.Point(8, 392)
        Me.lblKeitai.Name = "lblKeitai"
        Me.lblKeitai.Size = New System.Drawing.Size(128, 24)
        Me.lblKeitai.TabIndex = 10
        Me.lblKeitai.Text = "携帯電話番号"
        Me.lblKeitai.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblTansyuku
        '
        Me.lblTansyuku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblTansyuku.Location = New System.Drawing.Point(8, 424)
        Me.lblTansyuku.Name = "lblTansyuku"
        Me.lblTansyuku.Size = New System.Drawing.Size(128, 24)
        Me.lblTansyuku.TabIndex = 11
        Me.lblTansyuku.Text = "携帯短縮番号"
        Me.lblTansyuku.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblNaisen
        '
        Me.lblNaisen.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblNaisen.Location = New System.Drawing.Point(8, 456)
        Me.lblNaisen.Name = "lblNaisen"
        Me.lblNaisen.Size = New System.Drawing.Size(128, 24)
        Me.lblNaisen.TabIndex = 12
        Me.lblNaisen.Text = "内線番号"
        Me.lblNaisen.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblNyuusya
        '
        Me.lblNyuusya.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblNyuusya.Location = New System.Drawing.Point(8, 488)
        Me.lblNyuusya.Name = "lblNyuusya"
        Me.lblNyuusya.Size = New System.Drawing.Size(128, 24)
        Me.lblNyuusya.TabIndex = 13
        Me.lblNyuusya.Text = "入社年月日"
        Me.lblNyuusya.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblBlood
        '
        Me.lblBlood.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblBlood.Location = New System.Drawing.Point(8, 136)
        Me.lblBlood.Name = "lblBlood"
        Me.lblBlood.Size = New System.Drawing.Size(128, 24)
        Me.lblBlood.TabIndex = 14
        Me.lblBlood.Text = "血液型"
        Me.lblBlood.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'txtID
        '
        Me.txtID.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtID.Location = New System.Drawing.Point(144, 8)
        Me.txtID.Name = "txtID"
        Me.txtID.Size = New System.Drawing.Size(88, 23)
        Me.txtID.TabIndex = 1
        Me.txtID.Text = ""
        '
        'txtName
        '
        Me.txtName.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtName.Location = New System.Drawing.Point(144, 40)
        Me.txtName.Name = "txtName"
        Me.txtName.Size = New System.Drawing.Size(192, 23)
        Me.txtName.TabIndex = 2
        Me.txtName.Text = ""
        '
        'txtKana
        '
        Me.txtKana.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtKana.Location = New System.Drawing.Point(144, 72)
        Me.txtKana.Name = "txtKana"
        Me.txtKana.Size = New System.Drawing.Size(192, 23)
        Me.txtKana.TabIndex = 3
        Me.txtKana.Text = ""
        '
        'txtBirthDay
        '
        Me.txtBirthDay.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtBirthDay.Location = New System.Drawing.Point(144, 168)
        Me.txtBirthDay.Name = "txtBirthDay"
        Me.txtBirthDay.Size = New System.Drawing.Size(104, 23)
        Me.txtBirthDay.TabIndex = 6
        Me.txtBirthDay.Text = ""
        '
        'txtEmail
        '
        Me.txtEmail.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtEmail.Location = New System.Drawing.Point(144, 264)
        Me.txtEmail.Name = "txtEmail"
        Me.txtEmail.Size = New System.Drawing.Size(232, 23)
        Me.txtEmail.TabIndex = 9
        Me.txtEmail.Text = ""
        '
        'txtPost
        '
        Me.txtPost.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtPost.Location = New System.Drawing.Point(144, 296)
        Me.txtPost.Name = "txtPost"
        Me.txtPost.Size = New System.Drawing.Size(72, 23)
        Me.txtPost.TabIndex = 10
        Me.txtPost.Text = ""
        '
        'txtAddress
        '
        Me.txtAddress.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtAddress.Location = New System.Drawing.Point(144, 328)
        Me.txtAddress.Name = "txtAddress"
        Me.txtAddress.Size = New System.Drawing.Size(480, 23)
        Me.txtAddress.TabIndex = 11
        Me.txtAddress.Text = ""
        '
        'txtTel
        '
        Me.txtTel.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtTel.Location = New System.Drawing.Point(144, 360)
        Me.txtTel.Name = "txtTel"
        Me.txtTel.Size = New System.Drawing.Size(128, 23)
        Me.txtTel.TabIndex = 12
        Me.txtTel.Text = ""
        '
        'txtKeitai
        '
        Me.txtKeitai.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtKeitai.Location = New System.Drawing.Point(144, 392)
        Me.txtKeitai.Name = "txtKeitai"
        Me.txtKeitai.Size = New System.Drawing.Size(128, 23)
        Me.txtKeitai.TabIndex = 13
        Me.txtKeitai.Text = ""
        '
        'txtTansyuku
        '
        Me.txtTansyuku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtTansyuku.Location = New System.Drawing.Point(144, 424)
        Me.txtTansyuku.Name = "txtTansyuku"
        Me.txtTansyuku.Size = New System.Drawing.Size(80, 23)
        Me.txtTansyuku.TabIndex = 14
        Me.txtTansyuku.Text = ""
        '
        'txtNaisen
        '
        Me.txtNaisen.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtNaisen.Location = New System.Drawing.Point(144, 456)
        Me.txtNaisen.Name = "txtNaisen"
        Me.txtNaisen.Size = New System.Drawing.Size(80, 23)
        Me.txtNaisen.TabIndex = 15
        Me.txtNaisen.Text = ""
        '
        'txtNyuusya
        '
        Me.txtNyuusya.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.txtNyuusya.Location = New System.Drawing.Point(144, 488)
        Me.txtNyuusya.Name = "txtNyuusya"
        Me.txtNyuusya.Size = New System.Drawing.Size(112, 23)
        Me.txtNyuusya.TabIndex = 16
        Me.txtNyuusya.Text = ""
        '
        'btnSave
        '
        Me.btnSave.Font = New System.Drawing.Font("MS UI Gothic", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.btnSave.Location = New System.Drawing.Point(384, 464)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(112, 48)
        Me.btnSave.TabIndex = 17
        Me.btnSave.Text = "保存"
        '
        'btnReset
        '
        Me.btnReset.Font = New System.Drawing.Font("MS UI Gothic", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.btnReset.Location = New System.Drawing.Point(504, 464)
        Me.btnReset.Name = "btnReset"
        Me.btnReset.Size = New System.Drawing.Size(112, 48)
        Me.btnReset.TabIndex = 18
        Me.btnReset.Text = "リセット"
        '
        'cmbSex
        '
        Me.cmbSex.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.cmbSex.Items.AddRange(New Object() {"男性", "女性"})
        Me.cmbSex.Location = New System.Drawing.Point(144, 104)
        Me.cmbSex.Name = "cmbSex"
        Me.cmbSex.Size = New System.Drawing.Size(121, 24)
        Me.cmbSex.TabIndex = 4
        '
        'cmbBlood
        '
        Me.cmbBlood.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.cmbBlood.Items.AddRange(New Object() {"A型", "B型", "O型", "AB型"})
        Me.cmbBlood.Location = New System.Drawing.Point(144, 136)
        Me.cmbBlood.Name = "cmbBlood"
        Me.cmbBlood.Size = New System.Drawing.Size(121, 24)
        Me.cmbBlood.TabIndex = 5
        '
        'cmbSyozoku
        '
        Me.cmbSyozoku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.cmbSyozoku.Location = New System.Drawing.Point(144, 200)
        Me.cmbSyozoku.Name = "cmbSyozoku"
        Me.cmbSyozoku.Size = New System.Drawing.Size(121, 24)
        Me.cmbSyozoku.TabIndex = 7
        '
        'cmbYakusyoku
        '
        Me.cmbYakusyoku.Font = New System.Drawing.Font("MS UI Gothic", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.cmbYakusyoku.Location = New System.Drawing.Point(144, 232)
        Me.cmbYakusyoku.Name = "cmbYakusyoku"
        Me.cmbYakusyoku.Size = New System.Drawing.Size(121, 24)
        Me.cmbYakusyoku.TabIndex = 8
        '
        'frmAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(632, 518)
        Me.Controls.Add(Me.cmbYakusyoku)
        Me.Controls.Add(Me.cmbSyozoku)
        Me.Controls.Add(Me.cmbBlood)
        Me.Controls.Add(Me.cmbSex)
        Me.Controls.Add(Me.btnReset)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.txtNyuusya)
        Me.Controls.Add(Me.txtNaisen)
        Me.Controls.Add(Me.txtTansyuku)
        Me.Controls.Add(Me.txtKeitai)
        Me.Controls.Add(Me.txtTel)
        Me.Controls.Add(Me.txtAddress)
        Me.Controls.Add(Me.txtPost)
        Me.Controls.Add(Me.txtEmail)
        Me.Controls.Add(Me.txtBirthDay)
        Me.Controls.Add(Me.txtKana)
        Me.Controls.Add(Me.txtName)
        Me.Controls.Add(Me.txtID)
        Me.Controls.Add(Me.lblBlood)
        Me.Controls.Add(Me.lblNyuusya)
        Me.Controls.Add(Me.lblNaisen)
        Me.Controls.Add(Me.lblTansyuku)
        Me.Controls.Add(Me.lblKeitai)
        Me.Controls.Add(Me.lblAddress)
        Me.Controls.Add(Me.lblPost)
        Me.Controls.Add(Me.lblTel)
        Me.Controls.Add(Me.lblYakusyoku)
        Me.Controls.Add(Me.lblSyozoku)
        Me.Controls.Add(Me.lblBirthDay)
        Me.Controls.Add(Me.lblSex)
        Me.Controls.Add(Me.lblKana)
        Me.Controls.Add(Me.lblName)
        Me.Controls.Add(Me.lblID)
        Me.Controls.Add(Me.lblEMail)
        Me.Name = "frmAdd"
        Me.Text = "社員登録"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub CreateDataSet()
        scn = New SqlClient.SqlConnection("workstation id=SATAKEN95;" & _
                                "user id=sa;" & _
                                "password=sataken;" & _
                                "data source=SATA-XP2;" & _
                                "persist security info=False;" & _
                                "initial catalog=test;")
        scd.Connection = scn

    End Sub

    'フォームロード時のイベント
    Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CreateDataSet()
        scn.Open()
        sda = New SqlClient.SqlDataAdapter("SELECT * FROM 社員IDマスター", scn)
        sdaSyozoku = New SqlClient.SqlDataAdapter("SELECT * FROM 所属マスター", scn)
        sdaYakusyoku = New SqlClient.SqlDataAdapter("SELECT * FROM 役職マスター", scn)
        sda.Fill(ds, "社員IDマスター")
        sdaSyozoku.Fill(ds, "所属マスター")
        sdaYakusyoku.Fill(ds, "役職マスター")
        cmbSyozoku.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.ds, "所属マスター.所属ID"))
        cmbSyozoku.DataSource = ds
        cmbSyozoku.DisplayMember = "所属マスター.所属名"
        cmbSyozoku.ValueMember = "所属マスター.所属ID"
        cmbYakusyoku.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.ds, "役職マスター.役職ID"))
        cmbYakusyoku.DataSource = ds
        cmbYakusyoku.DisplayMember = "役職マスター.役職名"
        cmbYakusyoku.ValueMember = "役職マスター.役職ID"
        scn.Close()
        cmbSyozoku.SelectedValue = 1
        cmbYakusyoku.SelectedValue = 1
        cmbBlood.SelectedValue = "A型"
        cmbSex.SelectedItem = "男性"

    End Sub

    '保存ボタンが押された時のイベント
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim myCommand As New SqlClient.SqlCommandBuilder(sda)
        CreateDataSet()
        scd.CommandText = "SELECT 社員ID ,名前 ,ふりがな ,性別 ,生年月日 ,所属ID ,役職ID ,血液型 ,電子メール ,郵便番号 ,住所 ,自宅電話番号 ,携帯電話番号 ,携帯短縮番号 ,内線番号 ,入社年月日 " & " [社員IDマスター]"
        Dim myRow As System.Data.DataRow
        Dim myTable As New System.Data.DataTable
        myTable.Clear()
        If txtNyuusya.Text = "" Then        '入社年月日が記入されていないとき、1999年4月1日を代入する。
            txtNyuusya.Text = "1999/04/01"
        End If
        If txtBirthDay.Text = "" Then        '生年月日が記入されていないとき、1975年4月4日を代入する。
            txtBirthDay.Text = "1975/04/04"
        End If

        myTable = ds.Tables("社員IDマスター")   '保存先のテーブル名設定
        myRow = myTable.NewRow()                '新しいデータ列の設定

        'データ行の設定
        myRow("社員ID") = txtID.Text
        myRow("名前") = txtName.Text
        myRow("ふりがな") = txtKana.Text
        myRow("性別") = cmbSex.SelectedItem
        myRow("生年月日") = CDate(txtBirthDay.Text)
        myRow("所属ID") = cmbSyozoku.SelectedValue
        myRow("役職ID") = cmbYakusyoku.SelectedValue
        myRow("血液型") = cmbBlood.SelectedItem
        myRow("電子メール") = txtEmail.Text
        myRow("郵便番号") = txtPost.Text
        myRow("住所") = txtAddress.Text
        myRow("自宅電話番号") = txtTel.Text
        myRow("携帯電話番号") = txtKeitai.Text
        myRow("携帯短縮番号") = txtTansyuku.Text
        myRow("内線番号") = txtNaisen.Text
        myRow("入社年月日") = CDate(txtNyuusya.Text)

        '新しいデータ列を作成
        myTable.Rows.Add(myRow)
        sda.InsertCommand = myCommand.GetInsertCommand
        sda.Update(ds, "社員IDマスター")
        ds.Clear()

    End Sub

コマンドはこんな感じになっています。
なにか、改善するところはありますか?

編集 削除
soushi  2004-12-13 11:44:07  No: 118242  IP: [192.*.*.*]

ありがとうございました。

編集 削除