visual studio c#如何使用数据集查询结果填充列表框

时间:2013-05-08 20:52:11

标签: c# listbox dataset ms-access-2010

我是C#的新手并且已经遇到了问题。我正在编写一个程序来显示一天或一天​​之间分开的事件。我没有很多处理访问数据库的经验,但我听说它们比SQL数据库更容易使用。我正在使用搜索查询来查找每天的事件,然后将他们的“描述”元素放入列表框中,以适应一周中的适当日期。当我运行该程序工作正常,但没有用事件填充列表框。

我确信我的代码在许多方面都是非常错误的,但正如我所说,我仍在学习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;
}
}

谢谢

2 个答案:

答案 0 :(得分:1)

设置数据源后尝试调用listBox1.DataBind()。重复其余部分。

答案 1 :(得分:0)

我不知道您的数据集被调用了什么,但我们假设您使用SQL查询的结果填充了一个名为DataSet1的DataSet。您的列表框名为ListBox1。你需要做这样的事情:

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

OR

ListBox1.ItemsSource = DataSet1;

不确定哪一个有效,但我认为第二个很好。

希望这有帮助。