gpt4 book ai didi

c# - 如何在 C# 上更新和显示数据库结果

转载 作者:行者123 更新时间:2023-11-29 18:42:33 25 4
gpt4 key购买 nike

我正在尝试使用 C# 进行一些考试并创建一个学生系统。我在表格行的可视化方面遇到了一些问题。

我创建了文本框,我应该在其中放置学生的成绩。我输入了值,但是当我再次启动应用程序时,这些字段为空。当我打开表时 - 值就在那里。此后的另一个问题是:如果文本框中有成绩,并且我想更改它,我不会在表中创建另一行,我想更新当前学生的行。表之间的通信是单元格“id”和“Faculty Number”。

程序:

CREATE PROCEDURE [dbo].InsertGrades
@fakNum nvarchar(50),
@math int,
@physic int,
@pik int,
@oip int,
@saa int,
@ps int,
@pmu int,
@kp int,
@asls int,
@pe int
AS
INSERT INTO [Grades] (FakNumber, Math, Physic, PIK, OIP, SAA, PS, PMU, KP, ASLS, PE)
VALUES (@fakNum , @math, @physic, @pik, @oip, @saa, @ps, @pmu, @kp, @asls, @pe)

bool 无效:

public static bool InsertGrades(Grade grd)
{
GradesDataClassesDataContext grds = new GradesDataClassesDataContext();
try
{
grds.InsertGrades(grd.FakNumber, grd.Math, grd.Physic, grd.PIK, grd.OIP, grd.SAA, grd.PS, grd.PMU, grd.KP, grd.ASLS, grd.PE);
grds.SubmitChanges();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
return false;
}
return true;
}

另一个 bool 值:

public static bool InsertGrades(Grade g)
{
if (g.Math > 6 && g.Math < 2 &&
g.Physic > 6 && g.Physic < 2 &&
g.PIK > 6 && g.PIK < 2 &&
g.OIP > 6 && g.OIP < 2 &&
g.SAA > 6 && g.SAA < 2 &&
g.PS > 6 && g.PS < 2 &&
g.PMU > 6 && g.PMU < 2 &&
g.KP > 6 && g.KP < 2 &&
g.ASLS > 6 && g.ASLS < 2 &&
g.PE > 6 && g.PE < 2)

{
return UserData.InsertGrades(g);
}
else
{
return false;
}
}

这必须将值从表格插入文本框,但事实并非如此:

private Data.Grade ReadStudentGrades()
{
Data.Grade grd = new Data.Grade();
grd.FakNumber = txtFakNumber.Text;
grd.Math = Int32.Parse(txtMath.Text);
grd.Physic = Int32.Parse(txtPhysic.Text);
grd.PIK = Int32.Parse(txtPIK.Text);
grd.OIP = Int32.Parse(txtOIP.Text);
grd.SAA = Int32.Parse(txtSAA.Text);
grd.PS = Int32.Parse(txtPS.Text);
grd.PMU = Int32.Parse(txtPMU.Text);
grd.KP = Int32.Parse(txtKP.Text);
grd.ASLS = Int32.Parse(txtASLS.Text);
grd.PE = Int32.Parse(txtPE.Text);
grd.FakNumber = txtFakNumber.Text;

return grd;
}

最佳答案

关于此代码:

This must insert values from table to textboxes, but it doesn't:

private Data.Grade ReadStudentGrades()
{
Data.Grade grd = new Data.Grade();
grd.FakNumber = txtFakNumber.Text;
grd.Math = Int32.Parse(txtMath.Text);
grd.Physic = Int32.Parse(txtPhysic.Text);
grd.PIK = Int32.Parse(txtPIK.Text);
grd.OIP = Int32.Parse(txtOIP.Text);
grd.SAA = Int32.Parse(txtSAA.Text);
grd.PS = Int32.Parse(txtPS.Text);
grd.PMU = Int32.Parse(txtPMU.Text);
grd.KP = Int32.Parse(txtKP.Text);
grd.ASLS = Int32.Parse(txtASLS.Text);
grd.PE = Int32.Parse(txtPE.Text);
grd.FakNumber = txtFakNumber.Text;

return grd;
}

此代码无法将值从表插入到文本框。这里没有一行为任何文本框分配值。

也许你把它搞反了?也许应该更像这样:

private Data.Grade ReadStudentGrades()
{
Data.Grade grd = new Data.Grade();
txtFakNumber.Text = grd.FakNumber;
txtMath.Text = grd.Math.ToString();
txtPhysic.Text = grd.Physic.ToString();
txtPIK.Text = grd.PIK.ToString();
(txtOIP.Text = grd.OIP.ToString();
txtSAA.Text = grd.SAA.ToString();
txtPS.Text = grd.PS.ToString();
txtPMP.Text = grd.PMU.ToString();
txtKP.Text = grd.KP.ToString();
txtASLA.Text = grd.ASLS.ToString();
txtPE.Text = grd.PE.ToString();
txtFakNumber.Text = grd.FakNumber;

}

关于c# - 如何在 C# 上更新和显示数据库结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44855366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com