2009-07-20 4 views
1

鉱山の別のSQL問題..SQL Server CEリーダーの問題ですが、読んでいません!

リーダーが正しく動作しません。この時間(私はそう思う) 私はこのコードを使用して、私は唯一の1レコードが追加され、私のDBは、レコードの100`sあり得ます。..

public void addPosts() 
    { 

     string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\msgdb.sdf"; 

     string sql; 
     PictureBox avaBox = new PictureBox(); 
     PictureBox pictureBox1 = new PictureBox(); 
     Button atBtn = new Button(); 
     RichTextBox msgBox = new RichTextBox(); 
     Panel panelz = new Panel(); 
     DateTime dt = DateTime.Now; 
     SqlCeConnection connection = new SqlCeConnection("datasource=" + dbfile); 
     // Read all rows from the table test_table into a dataset (note, the adapter automatically opens the connection) 
     SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from posts", connection); 
     DataSet data = new DataSet(); 
     adapter.Fill(data); 

     SqlCeCommand cmd = new SqlCeCommand(); 
     cmd.Connection = connection; 
     sql = "Select user_from,msg,avatar FROM posts"; 
     cmd.CommandText = sql; 
     connection.Open(); 
     SqlCeDataReader reader = cmd.ExecuteReader(); 
     int i = 0; 
     while (reader.Read()) 
      { 
       i++; 
       string ava = reader.GetString(2); 
       string usrFrom = reader.GetString(0); 
       string messige = reader.GetString(1); 
       // 
       // groupBox1 
       // 
       panelz.Controls.Add(pictureBox1); 
       panelz.Controls.Add(atBtn); 
       panelz.Controls.Add(avaBox); 
       panelz.Controls.Add(msgBox); 
       panelz.Location = new System.Drawing.Point(0, 335); 
       panelz.Name = "panel"+ i; 
       panelz.Size = new System.Drawing.Size(335, 90); 

       panelz.TabIndex = 0; 
       panelz.TabStop = false; 


       // 
       // pictureBox1 
       // 
       pictureBox1.Dock = System.Windows.Forms.DockStyle.Right; 
       pictureBox1.Image = global::m23.Properties.Resources.post_area; 
       pictureBox1.Location = new System.Drawing.Point(58, 0); 
       pictureBox1.Name = "pictureBox1"+i; 
       pictureBox1.Size = new System.Drawing.Size(281, 99); 
       pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; 
       pictureBox1.TabIndex = 1; 
       pictureBox1.TabStop = false; 
       // 
       // atBtn 
       // 
       atBtn.AutoSize = true; 
       atBtn.BackgroundImage = global::m23.Properties.Resources.post_user; 
       atBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; 
       atBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; 
       atBtn.Location = new System.Drawing.Point(0, 62); 
       atBtn.Name = "atBtn"+i; 
       atBtn.Size = new System.Drawing.Size(28, 25); 
       atBtn.TabIndex = 2; 
       atBtn.UseVisualStyleBackColor = true; 

       // 
       avaBox.Location = new System.Drawing.Point(0, 0); 
       avaBox.Name = "avaBox"+i; 
       avaBox.Size = new System.Drawing.Size(53, 53); 
       avaBox.TabIndex = 4; 
       avaBox.TabStop = false; 
       avaBox.ImageLocation = "http://img.edno23.com/avatars/thumbs/" + ava; 

       // 
       msgBox.BorderStyle = System.Windows.Forms.BorderStyle.None; 
       msgBox.Location = new System.Drawing.Point(76, 10); 

       msgBox.Name = "msgBox"+i; 
       msgBox.ReadOnly = true; 
       msgBox.BackColor = Color.White; 
       msgBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; 
       msgBox.Size = new System.Drawing.Size(251, 68); 
       msgBox.TabIndex = 3; 
       msgBox.Text = messige; 
       msgBox.BringToFront(); 
       // 

       CommonFlowPanel.Controls.Add(panelz); 


      } 


     connection.Close(); 
    } 

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

答えて

2

パネルの宣言とwhileループの各パネルに表示されるすべてのコントロールを配置します。基本的には、Panel(「panelz」)の一度のインスタンスを何度も繰り返し追加しています。あなたがしたいのは、パネル上にある各コントロールの新しいインスタンスとともに、whileループの中に各行の新しいパネルを作成することです。

+0

AHH !!時にはそのシンプルな..私は、コードrigthを書くにはあまりにも疲れている私の推測:)答えのおかげで! – Aviatrix

関連する問題