怎么赋初值
protected void btnApplication_Click(object sender, EventArgs e)
{
string str = "";
string point = "";
string a = "0";
SqlConnection conn = BaseClass.DBCon();
for (int i = 0; i < DataList1.Items.Count; i++)
{
str = ((Label)(DataList1.Items[i].FindControl("SubjectIDLabel"))).Text.ToString().Trim();
point = ((TextBox)(DataList1.Items[i].FindControl("txtPoint"))).Text.ToString().Trim();
SqlCommand OldCmd = new SqlCommand("select 主观题分数 from exampaper where 试卷ID='" + str + "'", conn);
conn.Open();
a = OldCmd.ExecuteScalar().ToString();
float OldPoint = float.Parse(OldCmd.ExecuteScalar().ToString().Trim()) + float.Parse(point);
SqlCommand cmd = new SqlCommand("UPDATE [STS].[dbo].[exampaper] set 主观题分数=" + OldPoint + "where [试卷ID]='" + str + "'", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
上边的这段代码实现累加功能,我想在每次开始循环的时候清零开始循环?代码怎么写
------解决方案--------------------从零开始? 你可以把那个字段改成数字类型,默认值=0,然后下面直接累加就可以了,当然还有使用代码赋值