如何从UserControl获取数据以形成表单?C#WinForms和SQLite
我知道有人问过这个问题,但不幸的是,大多数答案并没有解决问题。所以希望有人能帮我:) 这就是我的问题 我想从StudentLedgerControl获取这些数据(我用红色包围了它)。然后将此数据传输到名为StudentLedgerWindow的表单中 尽管在此之前,必须单击一个按钮来显示StudentLedgerWindow,一旦显示,传输的数据就会出现 StudentLedgerControl.cs如何从UserControl获取数据以形成表单?C#WinForms和SQLite,c#,winforms,sqlite,C#,Winforms,Sqlite,我知道有人问过这个问题,但不幸的是,大多数答案并没有解决问题。所以希望有人能帮我:) 这就是我的问题 我想从StudentLedgerControl获取这些数据(我用红色包围了它)。然后将此数据传输到名为StudentLedgerWindow的表单中 尽管在此之前,必须单击一个按钮来显示StudentLedgerWindow,一旦显示,传输的数据就会出现 StudentLedgerControl.cs public void LoadStudentLedger(SQLiteConnection
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
public string _StudentName;
public string _StudentSection;
public string _StudentLevel;
public string _StudentId;
public string StudentName
{
get { return _StudentName; }
set { _StudentName = value; }
}
public string StudentSection
{
get { return _StudentSection; }
set { _StudentSection = value; }
}
public string StudentLevel
{
get { return _StudentLevel; }
set { _StudentLevel = value; }
}
public string StudentId
{
get { return _StudentId; }
set { _StudentId = value; }
}
StudentLedgerWindows(预期结果)
显示窗口按钮事件和用户界面
private void ViewLedgerButton_Click(object sender, EventArgs e)
{
// Once clicked, the data should show on StudentLedgerWindow
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentId = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentName = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSection = "Section: " + read.GetString(4); // section
sc.StudentLevel = "Level: " + read.GetInt32(5).ToString(); // level
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
提前感谢:)
另外,我是新来的,所以如果我的帖子有任何问题,请告诉我,以便我可以更改它。
我想我已经解决了。。。idk可能
我所做的就是创建getter和setter(kek,我应该先试试这个) 然后打电话给接受者和接受者。(如果这是有道理的,希望是有道理的) 旧代码private void ViewLedgerButton_Click(object sender, EventArgs e)
{
// Once clicked, the data should show on StudentLedgerWindow
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentId = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentName = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSection = "Section: " + read.GetString(4); // section
sc.StudentLevel = "Level: " + read.GetInt32(5).ToString(); // level
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
新代码
private void ViewLedgerButton_Click(object sender, EventArgs e)
{
// Once clicked, the data should show on StudentLedgerWindow
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentId = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentName = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSection = "Section: " + read.GetString(4); // section
sc.StudentLevel = "Level: " + read.GetInt32(5).ToString(); // level
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
能手和二传手
public void LoadStudentLedger(SQLiteConnection conn)
{
SQLiteCommand sqlite_cmd;
sqlite_cmd = new SQLiteCommand("SELECT * FROM Student", conn);
SQLiteDataReader read = sqlite_cmd.ExecuteReader();
StudentFlowPanel.SuspendLayout();
StudentFlowPanel.Controls.Clear();
while (read.Read())
{
sc = new StudentControl();
sc.StudentIDLabel.Text = "Student ID: " + read.GetInt32(0).ToString(); // id
sc.StudentNameLabel.Text = read.GetString(1) + " " + read.GetString(2) + " " + read.GetString(3); // fullname
sc.StudentSectionLabel.Text = "Section: " + read.GetString(4); // section
sc.StudentLevelLabel.Text = "Level: " + read.GetInt32(5).ToString(); // level
StudentFlowPanel.Controls.Add(sc);
}
StudentFlowPanel.ResumeLayout();
}
public string _StudentName;
public string _StudentSection;
public string _StudentLevel;
public string _StudentId;
public string StudentName
{
get { return _StudentName; }
set { _StudentName = value; }
}
public string StudentSection
{
get { return _StudentSection; }
set { _StudentSection = value; }
}
public string StudentLevel
{
get { return _StudentLevel; }
set { _StudentLevel = value; }
}
public string StudentId
{
get { return _StudentId; }
set { _StudentId = value; }
}
谢谢:)
另外,如果我能做任何代码改进,请告诉我:)恐怕这里不接受代码图片,其中一个关键原因是:我们无法调试图像!请在您的问题中以文本形式提供您的代码。好的,我的错。对不起,您的问题到底是什么?我想从usercontrol获取表单中的数据。