2013-05-08 60 views
0

我是C#的新手,已經遇到了問題。我正在編寫一個程序來顯示一週或一天中的事件。我沒有很多處理訪問數據庫的經驗,但我聽說他們可以比SQL數據庫更容易使用。我正在使用搜索查詢來查找每天的事件,然後將其「description」元素放入一週的適當日期的列表框中。當我運行程序時工作正常,但沒有填充事件的列表框。visual studio c#如何填充數據集查詢結果的列表框

我確信我的代碼在很多方面都很錯誤,但正如我所說我仍然在學習C#。我一直在尋找互聯網,並嘗試幾乎所有我能找到的「解決方案」,而迄今爲止沒有任何工作能夠實現。任何幫助深表感謝。 Windows窗體代碼如下:爲設計師

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace USA_ETK 
{ 
public partial class StartUp : Form 
{ 
    private DateTime tempToday = DateTime.Today; 
    private DateTime beginofweek; 
    private DateTime endofweek; 

    public StartUp() 
    { 
     InitializeComponent(); 
     findWeek(tempToday); 
     startUp_begin(); 
    } 

    private void newSessionsToolStripMenuItem_Click(object sender, EventArgs e) 
    { 
     New_Session newSessionWindow = new New_Session(); 
     newSessionWindow.Visible=true; 
    } 

    private void exitToolStripMenuItem_Click(object sender, EventArgs e) 
    { 
     Close(); 
    } 

    private void findWeek(DateTime tt) 
    { 

     DayOfWeek day = tt.DayOfWeek; 
     int days = day - DayOfWeek.Sunday; 
     beginofweek = tt.AddDays(-days); 
     endofweek = beginofweek.AddDays(6); 

     label8.Text = beginofweek.ToString("MM/dd/yyyy") + " - " + endofweek.ToString("MM/dd/yyyy"); 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     tempToday.AddDays(7); 
     findWeek(tempToday); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     tempToday.AddDays(-7); 
     findWeek(tempToday); 
    } 

    private void startUp_begin() 
    { 
     DateTime tempdate = new DateTime(beginofweek.Year, beginofweek.Month, beginofweek.Day, 00, 00, 00); 

     listBox1.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     //listBox2.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     listBox3.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     listBox4.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     listBox5.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     listBox6.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
     tempdate.AddDays(1); 
     listBox7.DataSource = session_LogTableAdapter.GetDataBySearch(tempdate.Date); 
    } 
} 
} 

代碼如下:

namespace USA_ETK 
{ 
partial class StartUp 
{ 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 
    private System.ComponentModel.IContainer components = null; 

    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
    protected override void Dispose(bool disposing) 
    { 
     if (disposing && (components != null)) 
     { 
      components.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    #region Windows Form Designer generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     this.components = new System.ComponentModel.Container(); 
     this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 
     this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.sessionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.newSessionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.editSessionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.customersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.newCustomerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.editCustomerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.employeesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.addNewEmployeeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.editEmployeeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.schedulingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.maintenanceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); 
     this.fYIToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.button1 = new System.Windows.Forms.Button(); 
     this.button2 = new System.Windows.Forms.Button(); 
     this.listBox1 = new System.Windows.Forms.ListBox(); 
     this.listBox2 = new System.Windows.Forms.ListBox(); 
     this.listBox3 = new System.Windows.Forms.ListBox(); 
     this.listBox4 = new System.Windows.Forms.ListBox(); 
     this.listBox5 = new System.Windows.Forms.ListBox(); 
     this.listBox6 = new System.Windows.Forms.ListBox(); 
     this.listBox7 = new System.Windows.Forms.ListBox(); 
     this.sessionLogBindingSource1 = new System.Windows.Forms.BindingSource(this.components); 
     this.uSA_DatabaseDataSet = new USA_ETK.USA_DatabaseDataSet(); 
     this.label1 = new System.Windows.Forms.Label(); 
     this.label2 = new System.Windows.Forms.Label(); 
     this.label3 = new System.Windows.Forms.Label(); 
     this.label4 = new System.Windows.Forms.Label(); 
     this.label5 = new System.Windows.Forms.Label(); 
     this.label6 = new System.Windows.Forms.Label(); 
     this.label7 = new System.Windows.Forms.Label(); 
     this.label8 = new System.Windows.Forms.Label(); 
     this.session_LogTableAdapter = new USA_ETK.USA_DatabaseDataSetTableAdapters.Session_LogTableAdapter(); 
     this.menuStrip1.SuspendLayout(); 
     ((System.ComponentModel.ISupportInitialize)(this.sessionLogBindingSource1)).BeginInit(); 
     ((System.ComponentModel.ISupportInitialize)(this.uSA_DatabaseDataSet)).BeginInit(); 
     this.SuspendLayout(); 
     // 
     // menuStrip1 
     // 
     this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.fileToolStripMenuItem, 
     this.sessionsToolStripMenuItem, 
     this.customersToolStripMenuItem, 
     this.employeesToolStripMenuItem, 
     this.aboutToolStripMenuItem}); 
     this.menuStrip1.Location = new System.Drawing.Point(0, 0); 
     this.menuStrip1.Name = "menuStrip1"; 
     this.menuStrip1.Size = new System.Drawing.Size(1184, 24); 
     this.menuStrip1.TabIndex = 0; 
     this.menuStrip1.Text = "menuStrip1"; 
     // 
     // fileToolStripMenuItem 
     // 
     this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.exitToolStripMenuItem}); 
     this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 
     this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); 
     this.fileToolStripMenuItem.Text = "File"; 
     // 
     // exitToolStripMenuItem 
     // 
     this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; 
     this.exitToolStripMenuItem.Size = new System.Drawing.Size(92, 22); 
     this.exitToolStripMenuItem.Text = "Exit"; 
     this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); 
     // 
     // sessionsToolStripMenuItem 
     // 
     this.sessionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.newSessionsToolStripMenuItem, 
     this.editSessionToolStripMenuItem}); 
     this.sessionsToolStripMenuItem.Name = "sessionsToolStripMenuItem"; 
     this.sessionsToolStripMenuItem.Size = new System.Drawing.Size(63, 20); 
     this.sessionsToolStripMenuItem.Text = "Sessions"; 
     // 
     // newSessionsToolStripMenuItem 
     // 
     this.newSessionsToolStripMenuItem.Name = "newSessionsToolStripMenuItem"; 
     this.newSessionsToolStripMenuItem.Size = new System.Drawing.Size(140, 22); 
     this.newSessionsToolStripMenuItem.Text = "New Session"; 
     this.newSessionsToolStripMenuItem.Click += new System.EventHandler(this.newSessionsToolStripMenuItem_Click); 
     // 
     // editSessionToolStripMenuItem 
     // 
     this.editSessionToolStripMenuItem.Name = "editSessionToolStripMenuItem"; 
     this.editSessionToolStripMenuItem.Size = new System.Drawing.Size(140, 22); 
     this.editSessionToolStripMenuItem.Text = "Edit Session"; 
     // 
     // customersToolStripMenuItem 
     // 
     this.customersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.newCustomerToolStripMenuItem, 
     this.editCustomerToolStripMenuItem}); 
     this.customersToolStripMenuItem.Name = "customersToolStripMenuItem"; 
     this.customersToolStripMenuItem.Size = new System.Drawing.Size(76, 20); 
     this.customersToolStripMenuItem.Text = "Customers"; 
     // 
     // newCustomerToolStripMenuItem 
     // 
     this.newCustomerToolStripMenuItem.Name = "newCustomerToolStripMenuItem"; 
     this.newCustomerToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.newCustomerToolStripMenuItem.Text = "New Customer"; 
     // 
     // editCustomerToolStripMenuItem 
     // 
     this.editCustomerToolStripMenuItem.Name = "editCustomerToolStripMenuItem"; 
     this.editCustomerToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.editCustomerToolStripMenuItem.Text = "Edit Customer"; 
     // 
     // employeesToolStripMenuItem 
     // 
     this.employeesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.addNewEmployeeToolStripMenuItem, 
     this.editEmployeeToolStripMenuItem, 
     this.schedulingToolStripMenuItem, 
     this.maintenanceToolStripMenuItem}); 
     this.employeesToolStripMenuItem.Name = "employeesToolStripMenuItem"; 
     this.employeesToolStripMenuItem.Size = new System.Drawing.Size(76, 20); 
     this.employeesToolStripMenuItem.Text = "Employees"; 
     // 
     // addNewEmployeeToolStripMenuItem 
     // 
     this.addNewEmployeeToolStripMenuItem.Name = "addNewEmployeeToolStripMenuItem"; 
     this.addNewEmployeeToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.addNewEmployeeToolStripMenuItem.Text = "New Employee"; 
     // 
     // editEmployeeToolStripMenuItem 
     // 
     this.editEmployeeToolStripMenuItem.Name = "editEmployeeToolStripMenuItem"; 
     this.editEmployeeToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.editEmployeeToolStripMenuItem.Text = "Edit Employee"; 
     // 
     // schedulingToolStripMenuItem 
     // 
     this.schedulingToolStripMenuItem.Name = "schedulingToolStripMenuItem"; 
     this.schedulingToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.schedulingToolStripMenuItem.Text = "Scheduling"; 
     // 
     // maintenanceToolStripMenuItem 
     // 
     this.maintenanceToolStripMenuItem.Name = "maintenanceToolStripMenuItem"; 
     this.maintenanceToolStripMenuItem.Size = new System.Drawing.Size(153, 22); 
     this.maintenanceToolStripMenuItem.Text = "Maintenance"; 
     // 
     // aboutToolStripMenuItem 
     // 
     this.aboutToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
     this.aboutToolStripMenuItem1, 
     this.fYIToolStripMenuItem}); 
     this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; 
     this.aboutToolStripMenuItem.Size = new System.Drawing.Size(52, 20); 
     this.aboutToolStripMenuItem.Text = "About"; 
     // 
     // aboutToolStripMenuItem1 
     // 
     this.aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1"; 
     this.aboutToolStripMenuItem1.Size = new System.Drawing.Size(107, 22); 
     this.aboutToolStripMenuItem1.Text = "About"; 
     // 
     // fYIToolStripMenuItem 
     // 
     this.fYIToolStripMenuItem.Name = "fYIToolStripMenuItem"; 
     this.fYIToolStripMenuItem.Size = new System.Drawing.Size(107, 22); 
     this.fYIToolStripMenuItem.Text = "FAQ"; 
     // 
     // button1 
     // 
     this.button1.Location = new System.Drawing.Point(12, 27); 
     this.button1.Name = "button1"; 
     this.button1.Size = new System.Drawing.Size(100, 30); 
     this.button1.TabIndex = 1; 
     this.button1.Text = "<--------"; 
     this.button1.UseVisualStyleBackColor = true; 
     this.button1.Click += new System.EventHandler(this.button1_Click); 
     // 
     // button2 
     // 
     this.button2.Location = new System.Drawing.Point(1072, 27); 
     this.button2.Name = "button2"; 
     this.button2.Size = new System.Drawing.Size(100, 30); 
     this.button2.TabIndex = 2; 
     this.button2.Text = "-------->"; 
     this.button2.UseVisualStyleBackColor = true; 
     this.button2.Click += new System.EventHandler(this.button2_Click); 
     // 
     // listBox1 
     // 
     this.listBox1.DataSource = this.sessionLogBindingSource1; 
     this.listBox1.DisplayMember = "Description"; 
     this.listBox1.FormattingEnabled = true; 
     this.listBox1.Location = new System.Drawing.Point(12, 84); 
     this.listBox1.Name = "listBox1"; 
     this.listBox1.Size = new System.Drawing.Size(160, 524); 
     this.listBox1.TabIndex = 3; 
     // 
     // listBox2 
     // 
     this.listBox2.DataSource = this.sessionLogBindingSource1; 
     this.listBox2.DisplayMember = "Description"; 
     this.listBox2.FormattingEnabled = true; 
     this.listBox2.Location = new System.Drawing.Point(178, 84); 
     this.listBox2.Name = "listBox2"; 
     this.listBox2.Size = new System.Drawing.Size(160, 524); 
     this.listBox2.TabIndex = 4; 
     // 
     // listBox3 
     // 
     this.listBox3.DataSource = this.sessionLogBindingSource1; 
     this.listBox3.DisplayMember = "Description"; 
     this.listBox3.FormattingEnabled = true; 
     this.listBox3.Location = new System.Drawing.Point(344, 84); 
     this.listBox3.Name = "listBox3"; 
     this.listBox3.Size = new System.Drawing.Size(160, 524); 
     this.listBox3.TabIndex = 5; 
     // 
     // listBox4 
     // 
     this.listBox4.DataSource = this.sessionLogBindingSource1; 
     this.listBox4.DisplayMember = "Description"; 
     this.listBox4.FormattingEnabled = true; 
     this.listBox4.Location = new System.Drawing.Point(510, 84); 
     this.listBox4.Name = "listBox4"; 
     this.listBox4.Size = new System.Drawing.Size(160, 524); 
     this.listBox4.TabIndex = 6; 
     // 
     // listBox5 
     // 
     this.listBox5.DataSource = this.sessionLogBindingSource1; 
     this.listBox5.DisplayMember = "Description"; 
     this.listBox5.FormattingEnabled = true; 
     this.listBox5.Location = new System.Drawing.Point(676, 84); 
     this.listBox5.Name = "listBox5"; 
     this.listBox5.Size = new System.Drawing.Size(160, 524); 
     this.listBox5.TabIndex = 7; 
     // 
     // listBox6 
     // 
     this.listBox6.DataSource = this.sessionLogBindingSource1; 
     this.listBox6.DisplayMember = "Description"; 
     this.listBox6.FormattingEnabled = true; 
     this.listBox6.Location = new System.Drawing.Point(842, 84); 
     this.listBox6.Name = "listBox6"; 
     this.listBox6.Size = new System.Drawing.Size(160, 524); 
     this.listBox6.TabIndex = 8; 
     // 
     // listBox7 
     // 
     this.listBox7.DataSource = this.sessionLogBindingSource1; 
     this.listBox7.DisplayMember = "Description"; 
     this.listBox7.FormattingEnabled = true; 
     this.listBox7.Location = new System.Drawing.Point(1008, 84); 
     this.listBox7.Name = "listBox7"; 
     this.listBox7.Size = new System.Drawing.Size(160, 524); 
     this.listBox7.TabIndex = 9; 
     // 
     // sessionLogBindingSource1 
     // 
     this.sessionLogBindingSource1.DataMember = "Session_Log"; 
     this.sessionLogBindingSource1.DataSource = this.uSA_DatabaseDataSet; 
     // 
     // uSA_DatabaseDataSet 
     // 
     this.uSA_DatabaseDataSet.DataSetName = "USA_DatabaseDataSet"; 
     this.uSA_DatabaseDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; 
     // 
     // label1 
     // 
     this.label1.AutoSize = true; 
     this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label1.Location = new System.Drawing.Point(56, 64); 
     this.label1.Name = "label1"; 
     this.label1.Size = new System.Drawing.Size(56, 17); 
     this.label1.TabIndex = 17; 
     this.label1.Text = "Sunday"; 
     // 
     // label2 
     // 
     this.label2.AutoSize = true; 
     this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label2.Location = new System.Drawing.Point(221, 64); 
     this.label2.Name = "label2"; 
     this.label2.Size = new System.Drawing.Size(58, 17); 
     this.label2.TabIndex = 18; 
     this.label2.Text = "Monday"; 
     // 
     // label3 
     // 
     this.label3.AutoSize = true; 
     this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label3.Location = new System.Drawing.Point(391, 64); 
     this.label3.Name = "label3"; 
     this.label3.Size = new System.Drawing.Size(63, 17); 
     this.label3.TabIndex = 19; 
     this.label3.Text = "Tuesday"; 
     // 
     // label4 
     // 
     this.label4.AutoSize = true; 
     this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label4.Location = new System.Drawing.Point(543, 64); 
     this.label4.Name = "label4"; 
     this.label4.Size = new System.Drawing.Size(83, 17); 
     this.label4.TabIndex = 20; 
     this.label4.Text = "Wednesday"; 
     // 
     // label5 
     // 
     this.label5.AutoSize = true; 
     this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label5.Location = new System.Drawing.Point(722, 64); 
     this.label5.Name = "label5"; 
     this.label5.Size = new System.Drawing.Size(68, 17); 
     this.label5.TabIndex = 21; 
     this.label5.Text = "Thursday"; 
     // 
     // label6 
     // 
     this.label6.AutoSize = true; 
     this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label6.Location = new System.Drawing.Point(896, 64); 
     this.label6.Name = "label6"; 
     this.label6.Size = new System.Drawing.Size(47, 17); 
     this.label6.TabIndex = 22; 
     this.label6.Text = "Friday"; 
     // 
     // label7 
     // 
     this.label7.AutoSize = true; 
     this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label7.Location = new System.Drawing.Point(1053, 64); 
     this.label7.Name = "label7"; 
     this.label7.Size = new System.Drawing.Size(65, 17); 
     this.label7.TabIndex = 23; 
     this.label7.Text = "Saturday"; 
     // 
     // label8 
     // 
     this.label8.AutoSize = true; 
     this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.label8.Location = new System.Drawing.Point(506, 28); 
     this.label8.Name = "label8"; 
     this.label8.Size = new System.Drawing.Size(0, 24); 
     this.label8.TabIndex = 24; 
     this.label8.TextAlign = System.Drawing.ContentAlignment.TopCenter; 
     // 
     // session_LogTableAdapter 
     // 
     this.session_LogTableAdapter.ClearBeforeFill = true; 
     // 
     // StartUp 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(1184, 620); 
     this.Controls.Add(this.label8); 
     this.Controls.Add(this.label7); 
     this.Controls.Add(this.label6); 
     this.Controls.Add(this.label5); 
     this.Controls.Add(this.label4); 
     this.Controls.Add(this.label3); 
     this.Controls.Add(this.label2); 
     this.Controls.Add(this.label1); 
     this.Controls.Add(this.listBox7); 
     this.Controls.Add(this.listBox6); 
     this.Controls.Add(this.listBox5); 
     this.Controls.Add(this.listBox4); 
     this.Controls.Add(this.listBox3); 
     this.Controls.Add(this.listBox2); 
     this.Controls.Add(this.listBox1); 
     this.Controls.Add(this.button2); 
     this.Controls.Add(this.button1); 
     this.Controls.Add(this.menuStrip1); 
     this.MainMenuStrip = this.menuStrip1; 
     this.Name = "StartUp"; 
     this.Text = "Union Sports Arena - Employee Tool Kit"; 
     this.menuStrip1.ResumeLayout(false); 
     this.menuStrip1.PerformLayout(); 
     ((System.ComponentModel.ISupportInitialize)(this.sessionLogBindingSource1)).EndInit(); 
     ((System.ComponentModel.ISupportInitialize)(this.uSA_DatabaseDataSet)).EndInit(); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 

    #endregion 

    private System.Windows.Forms.MenuStrip menuStrip1; 
    private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem sessionsToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem newSessionsToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem editSessionToolStripMenuItem; 
    private System.Windows.Forms.Button button1; 
    private System.Windows.Forms.Button button2; 
    private System.Windows.Forms.ListBox listBox1; 
    private System.Windows.Forms.ListBox listBox2; 
    private System.Windows.Forms.ListBox listBox3; 
    private System.Windows.Forms.ListBox listBox4; 
    private System.Windows.Forms.ListBox listBox5; 
    private System.Windows.Forms.ListBox listBox6; 
    private System.Windows.Forms.ListBox listBox7; 
    private System.Windows.Forms.Label label1; 
    private System.Windows.Forms.Label label2; 
    private System.Windows.Forms.Label label3; 
    private System.Windows.Forms.Label label4; 
    private System.Windows.Forms.Label label5; 
    private System.Windows.Forms.Label label6; 
    private System.Windows.Forms.Label label7; 
    private System.Windows.Forms.Label label8; 
    private System.Windows.Forms.ToolStripMenuItem customersToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem newCustomerToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem editCustomerToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem employeesToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem addNewEmployeeToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem editEmployeeToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem schedulingToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem maintenanceToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; 
    private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem1; 
    private System.Windows.Forms.ToolStripMenuItem fYIToolStripMenuItem; 
    private USA_DatabaseDataSet uSA_DatabaseDataSet; 
    private System.Windows.Forms.BindingSource sessionLogBindingSource1; 
    private USA_DatabaseDataSetTableAdapters.Session_LogTableAdapter session_LogTableAdapter; 
} 
} 

謝謝

+0

您的數據集在哪裏申報?你在哪裏填寫你的查詢結果? – 2013-05-08 22:03:40

回答

1

嘗試設置數據源後調用listBox1.DataBind()。重複其餘的人。

0

我不知道你的數據集被調用了什麼,但是讓我們假設你用一個SQL查詢的結果填充了一個名爲DataSet1的DataSet。而你的列表框被稱爲ListBox1。你需要做這樣的事情:

ListBox1.ItemsSource = DataSet1.Tables["tablename"]; 

OR

ListBox1.ItemsSource = DataSet1; 

不知道哪一個作品,我覺得第二個是好的,但。

希望這會有所幫助。

相關問題