c# VS中怎么讲计算出来的成绩插入sql数据库,语句是什么?
相应代码:(想把得到的成绩插入数据库)namespaceMySchool{publicpartialclassQuizResultForm:Form{publicQuiz...
相应代码:(想把得到的成绩插入数据库)
namespace MySchool
{
public partial class QuizResultForm : Form
{
public QuizResultForm()
{
InitializeComponent();
}
// 退出应用程序
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
// 显示分数
private void QuizResultForm_Load(object sender, EventArgs e)
{
// 计算答对的题目数量
int correctNum = 0;
for (int i = 0; i < QuizHelper.questionNum; i++)
{
if (QuizHelper.studentAnswers[i] == QuizHelper.correctAnswers[i])
{
correctNum++;
}
}
// 计算得分
int score = correctNum * 100 / QuizHelper.questionNum;
lblMark.Text = score.ToString()+"分";
lblStudentScoreStrip.Width = lblFullMarkStrip.Width * score / 100; 展开
namespace MySchool
{
public partial class QuizResultForm : Form
{
public QuizResultForm()
{
InitializeComponent();
}
// 退出应用程序
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
// 显示分数
private void QuizResultForm_Load(object sender, EventArgs e)
{
// 计算答对的题目数量
int correctNum = 0;
for (int i = 0; i < QuizHelper.questionNum; i++)
{
if (QuizHelper.studentAnswers[i] == QuizHelper.correctAnswers[i])
{
correctNum++;
}
}
// 计算得分
int score = correctNum * 100 / QuizHelper.questionNum;
lblMark.Text = score.ToString()+"分";
lblStudentScoreStrip.Width = lblFullMarkStrip.Width * score / 100; 展开
1个回答
展开全部
string sql = "insert into 数据库名(要插入的字段) values('" + 插入的值(如score) + "' )";
string strConn = @"Data Source =ACER-PC\SQLEXPRESS;Initial Catalog =GD;Integrated Security=true";
SqlConnection con = new SqlConnection(strConn)
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string strConn = @"Data Source =ACER-PC\SQLEXPRESS;Initial Catalog =GD;Integrated Security=true";
SqlConnection con = new SqlConnection(strConn)
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询