您好我正在尝试将数据库中的数据存储到变量中,然后尝试处理它。但不知何故,该变量不会从数据库中读取任何数据并给出其初始值。这是代码
int c1=0,c2=0.c3=0,c4=0,sum;
if (rbFour.Checked == true)
{
proce = cmb1.Text + "," + cmb2.Text + "," + cmb3.Text + "," + cmb4.Text;
SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
DataTable t = new DataTable();
foreach (DataRow row in t.Rows)
{
c1 = Convert.ToInt32(row[0]);
}
SqlDataAdapter qd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb2.ValueMember, Program.con);
DataTable qt = new DataTable();
foreach (DataRow row in qt.Rows)
{
c2 = Convert.ToInt32(row[0]);
}
SqlDataAdapter wd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb3.ValueMember, Program.con);
DataTable wt = new DataTable();
foreach (DataRow row in wt.Rows)
{
c3 = Convert.ToInt32(row[0]);
}
SqlDataAdapter ed = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb4.ValueMember, Program.con);
DataTable et = new DataTable();
foreach (DataRow row in et.Rows)
{
c4 = Convert.ToInt32(row[0]);
}
}
else if (rbThree.Checked == true)
{
proce = cmb1.Text + "," + cmb2.Text + "," + cmb3.Text;
SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
DataTable t = new DataTable();
foreach (DataRow row in t.Rows)
{
c1 = Convert.ToInt32(row[0]);
}
SqlDataAdapter qd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb2.ValueMember, Program.con);
DataTable qt = new DataTable();
foreach (DataRow row in qt.Rows)
{
c2 = Convert.ToInt32(row[0]);
}
SqlDataAdapter wd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb3.ValueMember, Program.con);
DataTable wt = new DataTable();
foreach (DataRow row in wt.Rows)
{
c3 = Convert.ToInt32(row[0]);
}
}
else if (rbTwo.Checked == true)
{
proce = cmb1.Text + "," + cmb2.Text;
SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
DataTable t = new DataTable();
foreach (DataRow row in t.Rows)
{
c1 = Convert.ToInt32(row[0]);
}
SqlDataAdapter qd = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb2.ValueMember, Program.con);
DataTable qt = new DataTable();
qd.Fill(qt);
foreach (DataRow row in qt.Rows)
{
c2 = Convert.ToInt32(row[0]);
}
}
else
{
proce = cmb1.Text;
SqlDataAdapter d = new SqlDataAdapter("Select Amount from addpro where SSN=" + cmb1.ValueMember, Program.con);
DataTable t = new DataTable();
foreach (DataRow row in t.Rows)
{
c1 = Convert.ToInt32(row[0]);
}
}
任何人都可以帮助解决这个问题。我几天前使用了相同的代码。它工作正常。但现在我不知道它有什么问题。我需要尽快解决,有人可以帮忙吗?