<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chibiegg日誌 &#187; Windowsプログラミング</title>
	<atom:link href="http://blog.chibiegg.net/category/%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/windows%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chibiegg.net</link>
	<description>chibiegg’s Diary</description>
	<lastBuildDate>Fri, 06 Jan 2012 01:51:23 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>DataGridViewの列をふりがなで並び替え[VB]</title>
		<link>http://blog.chibiegg.net/2007/12/02_15_100.htm</link>
		<comments>http://blog.chibiegg.net/2007/12/02_15_100.htm#comments</comments>
		<pubDate>Sun, 02 Dec 2007 06:18:32 +0000</pubDate>
		<dc:creator>chibiegg</dc:creator>
				<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[Windowsプログラミング]]></category>

		<guid isPermaLink="false">http://chibiegg.homeip.net/2007/12/02_15_100.htm</guid>
		<description><![CDATA[メモとして。 方法としては「名前」と「ふりがな」データを持つクラスをつくり「ToString」では「名前」を返し、比較は「ふりがな」でするようにします。 StringWithClass.vb Imports System [...]]]></description>
			<content:encoded><![CDATA[<p>メモとして。</p>
<p>方法としては「名前」と「ふりがな」データを持つクラスをつくり「ToString」では「名前」を返し、比較は「ふりがな」でするようにします。<br />
<span id="more-100"></span><br />
StringWithClass.vb</p>
<pre><code>Imports System
Imports System.Collections

Public Class StringWithKanaClass
    ' IComparableインターフェイスをインプリメント
    Implements IComparable

    ' メンバ
    Public Name As String
    Public Kana As String

    Public Sub New()
    End Sub

    Public Sub New(ByVal Name As String, ByVal Kana As String)
        MyClass.Name = Name
        MyClass.Kana = Kana
    End Sub

    ' ToString()は「Name」を返す
    Public Overrides Function ToString() As String
        Return Name
    End Function

    '比較する関数
    Public Function CompareTo(ByVal o As Object) As _
                                    Integer Implements IComparable.CompareTo
        '自分と同じ型の場合のみ比較
        If TypeOf o Is StringWithKanaClass Then
            Dim g As StringWithKanaClass = CType(o, StringWithKanaClass)
            Select Case Me.Kana.CompareTo(g.Kana)
                Case 0
                    Return 0
                Case Is > 0
                    Return 1
                Case Is < 0
                    Return -1
            End Select
        End If
        Return 0
    End Function
End Class</code></pre>
<p>DetaGridViewのセルには以下のように代入</p>
<pre><code>DataGridView1(c, i).Value = New StringWithKanaClass("名前","なまえ")</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.chibiegg.net/2007/12/02_15_100.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataGridViewにMySQLからデータを取得[VB]</title>
		<link>http://blog.chibiegg.net/2007/11/28_23_97.htm</link>
		<comments>http://blog.chibiegg.net/2007/11/28_23_97.htm#comments</comments>
		<pubDate>Wed, 28 Nov 2007 14:20:00 +0000</pubDate>
		<dc:creator>chibiegg</dc:creator>
				<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[Windowsプログラミング]]></category>
		<category><![CDATA[VisualBasic]]></category>

		<guid isPermaLink="false">http://chibiegg.homeip.net/2007/11/28_23_97.htm</guid>
		<description><![CDATA[ちょっとVB 2005からMySQLのデータを使うということをやりたいのでわかった順番にいろいろと書いていこうと思います。 今回はまずDataGridViewをつかってMySQLのデータベースからテーブルの中身を取得し表 [...]]]></description>
			<content:encoded><![CDATA[<p>ちょっとVB 2005からMySQLのデータを使うということをやりたいのでわかった順番にいろいろと書いていこうと思います。</p>
<p>今回はまずDataGridViewをつかってMySQLのデータベースからテーブルの中身を取得し表示しようと思います。<br />
サンプルにつかったデータは日本郵便の大阪府の<a href="http://www.post.japanpost.jp/zipcode/dl/kogaki.html">郵便番号データ</a>です。<br />
<span id="more-97"></span><br />
と思ったらphpMyAdminから郵便番号情報のインポートを説明する<a href="http://plaza.rakuten.co.jp/pgmemo/diary/200512110000/">サイト</a>がありました。</p>
<p>で、「japanpost」というデータベースに「zipcode」というテーブルを作成しそこにデータをインポートしました。<br />
特にデータベースの内容は問わないのでこれにあわせる必要はありません。</p>
<p>追記：データベースの照合順序はsjis_japanese_ciにします。UTF8ではWindowsでODBCから開いたときに文字化けしました。</p>
<p>それと、ODBC経由でMySQLに接続するデータベースドライバ「<a href="http://dev.mysql.com/downloads/connector/odbc/5.1.html">MySQL Connector/ODBC 5.1</a>」を<a href="http://dev.mysql.com/downloads/connector/odbc/5.1.html">ここ</a>からダウンロードしインストールしておきます。</p>
<p>ではプログラムの作成をします。</p>
<p><code>"DRIVER={MySQL ODBC 5.1 Driver};SERVER=(サーバーのアドレス);DATABASE=(データベース名);UID=(ユーザー名);PWD=(パスワード);OPTION=3"</code><br />
の様な接続文字列を作りサーバーにODBCで接続し、</p>
<p><code>"SELECT * FROM zipcode"</code><br />
というSQLを発行します。<br />
(ここを変えることで違うクエリを発行できます。)</p>
<p>そしてその結果を<br />
<code>DAdapter.Fill(DSet, "テーブル名")</code><br />
Fill関数を使ってDataSetに(テーブル名)という名前のテーブルで登録します。<br />
このテーブル名はプログラム上に作成されるテーブルなのでMySQLサーバーでのテーブル名とは異なるものでも構いません。</p>
<p>最後に<br />
<code>DataGridView1.DataSource = DSet.Tables("テーブル名")</code><br />
でDataSetの(テーブル名)というテーブルをDataGridViewのデータソースに指定します。</p>
<p>具体的なコードは以下を参照してください。<br />
サーバーアドレス「192.168.1.50」にユーザー名「test」パスワード「testpass」で接続し、<br />
データベース「japanpost」のテーブル「zipcode」を取得しDetaGridViewに表示するサンプルです。</p>
<p>実行してボタンを押した結果<br />
<a href='http://blog.chibiegg.net/wp-content/uploads/2007/11/sqltest-form1-exec.jpg' title='sqltest-form1-exec.jpg'><img src='http://blog.chibiegg.net/wp-content/uploads/2007/11/sqltest-form1-exec.thumbnail.jpg' alt='sqltest-form1-exec.jpg' /></a></p>
<p>「Form1」に以下のようにコントロールを配置します。</p>
<p>「DataGridView1」という名前でDetaGridViewを(濃い灰色の枠)<br />
「Button1」という名前でButtonを作ります(「実行」というボタン)<br />
<img src='http://blog.chibiegg.net/wp-content/uploads/2007/11/sqltest-form1.jpg' alt='sqltest-form1.jpg' /></p>
<p>Form1のコード</p>
<pre><code>Public Class Form1
    Dim DSet As New System.Data.DataSet
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ConnectionString As String = "DRIVER={MySQL ODBC 5.1 Driver};" &#038; _
                                            "SERVER=192.168.1.50;" &#038; _
                                            "DATABASE=japanpost;" &#038; _
                                            "UID=test;PWD=testpass;OPTION=3"

        Dim connection As New System.Data.Odbc.OdbcConnection(ConnectionString)
        connection.Open()

        Dim SQLTest As String = "SELECT * FROM zipcode"
        Dim DAdapter As New System.Data.Odbc.OdbcDataAdapter(SQLTest, connection)

        DAdapter.Fill(DSet, "zipcode")
        DataGridView1.DataSource = DSet.Tables("zipcode")

        connection.Close()
    End Sub
End Class</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.chibiegg.net/2007/11/28_23_97.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.chibiegg.net/category/%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/windows%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/feed ) in 0.23827 seconds, on Feb 8th, 2012 at 7:16 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 8:16 am UTC -->
