我正在使用向导控件让用户完成多个步骤。他们从第 1 步开始,但如果他们回答是或否(单选按钮),有时会跳过一些步骤。例如,某些步骤结束时的问题是:“问题解决了吗?” 并且有一个是或否单选按钮选择。如果答案是肯定的,请将他们带到最后一步完成。如果答案是否定的,那么他们进入下一步。
我的问题是从数据库中表测试的所有步骤中获取结果。
string constring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ClientMonitorDevices"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand();
cmd = conn.CreateCommand();
cmd.CommandText = @"INSERT INTO test (siteid, hotelname, step1, step2)
VALUES (@siteid, @hotelname, @step1, @step2)";
cmd.Parameters.AddWithValue("@siteid", siteid);
cmd.Parameters.AddWithValue("@hotelname", hotelname);
int activeStep = Wizard1.ActiveStepIndex;
switch (activeStep)
{
case 1:
if (step1_yes.Checked)
{
step1 = "Device Can Detect Network with a Signal Strength of 50% or Greater";
Wizard1.ActiveStepIndex = 2;
}
else if (step1_no.Checked)
{
step1 = "Device Cannot Detect Network with a Signal Strength of 50% or Greater";
Wizard1.ActiveStepIndex = 16;
}
else
{
e.Cancel = true;
gen.MessagBox(this.Page, "Please choose Yes or No", "Please choose Yes or No");
}
cmd.Parameters.AddWithValue("@step1", step1);
break;
case 2:
if (step2_unable.Checked)
{
step2 = "Unable to Join Network";
Wizard1.ActiveStepIndex = 3;
}
else if (step2_unidentified.Checked)
{
step2 = "Connect to Unidentified Network";
Wizard1.ActiveStepIndex = 7;
}
else if (step2_internet.Checked)
{
step2 = "Connected (Internet Access)";
Wizard1.ActiveStepIndex = 11;
}
else if (step2_local.Checked)
{
step2 = "Connected Local Only (No Internet Access)";
Wizard1.ActiveStepIndex = 15;
}
else
{
e.Cancel = true;
gen.MessagBox(this.Page, "Please Choose One of the Options", "Please Choose One of the Options");
}
cmd.Parameters.AddWithValue("@step2", step2);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
break;
我得到的错误是必须声明标量变量“@step1”。因为 step1 超出了范围,或者这就是我的想法。我尝试了一个存储过程,但这也不起作用。
另一种尝试是使用更新语句,但我遇到的问题是获取可索引的 ID 列(索引),并且每次插入都会增加 1。如果有人有任何想法,请务必告诉我。我已经为此工作了大约 2 周,但无济于事。