哈希表的用途是什么?asp.NETC
嗨 哈希表的用途是什么?我可以使用哈希表在按钮的点击事件中从数据库中移动记录吗?如果是,那么如何可能? 多谢各位哈希表的用途是什么?asp.NETC,asp.net,Asp.net,嗨 哈希表的用途是什么?我可以使用哈希表在按钮的点击事件中从数据库中移动记录吗?如果是,那么如何可能? 多谢各位 //This is the function i used to get next record from database public void getNextQuestion() { if (Convert.ToInt32(Session["counter"].ToString()) < 7) { if (R
//This is the function i used to get next record from database
public void getNextQuestion()
{
if (Convert.ToInt32(Session["counter"].ToString()) < 7)
{
if (RblOption.SelectedIndex >= 0)
{
string str1 = "";
SqlDataAdapter da3 = new SqlDataAdapter(str1, sqlconn);
Session["selans"] = RblOption.SelectedIndex.ToString();
if (Session["Answer"].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;
txtScore.Text = score.ToString();
lblScore.Text = "Score : " + Convert.ToString(score);
}
//Random rnd = new Random();
//var i = rnd.Next(1, 6);
SqlDataAdapter da = new SqlDataAdapter("select Q_id from Test_Final where Serial='1' order by Q_id", sqlconn);
DataSet ds = new DataSet();
da.Fill(ds, "Test_Final");
if (ds.Tables[0].Rows.Count > 0)
{
myArray = new int[ds.Tables[0].Rows.Count];
bool flag;
for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
{
myArray[i] = Convert.ToInt32(ds.Tables[0].Rows[i]["Q_id"].ToString());
//Response.Write(myArray[i]);
Random random = new Random();
int randomNo = random.Next(0, myArray.Length);
flag = true;
for (int x = 0; x < myArray.Length; x++)
{
if (randomNo == myArray[x])
{
i--;
flag = false;
break;
}
}
if (flag)
myArray[i] = randomNo;
}
Session["counter"] = Convert.ToString(Convert.ToInt32(Session["counter"].ToString()) + 1);
getQuestion(myArray[z]);
}
else
{
RegisterStartupScript("myAlert", "<script>alert('Please select the option')</script>");
}
}
else
{
Response.Redirect("Default.aspx");
}
}
}
单击按钮添加代码,如下所示 受保护的无效按钮1\u单击对象发送者,事件参数e { int键; string name=string.Empty; string str=string.Empty; Hashtable Hashtable=新的Hashtable; 键=1; name=Jake; Addkey,名称; 键=2; 姓名=彼得; Addkey,名称; 密钥=3; 姓名=莉莉; Addkey,名称; foreach字典在哈希表中输入de { str=str+key=+de.key++value=+de.value.ToString+; } } 如果我正确地得到了你,那么你想要这样的东西
public Hashtable Createashtable(string keyColumnName, DataTable table)
{
Hashtable hash = new Hashtable();
for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++)
{
hash.Add(table.Rows[rowIndex][keyColumnName], table.Rows[rowIndex]);
}
return hash;
}
}
是的,您可能会在这个过程中涉及一个哈希表;如何将表中的项目添加到哈希表中?您能否解释一下为什么您认为需要哈希表?实际上,我想在单击“下一步”按钮后移动下一条记录我使用了我发布的代码,但它得到了重复的值我必须从数据库中获取数据。我使用数据集获取数据,但我想从第一条记录移动到下一条记录,直到结束。那怎么可能呢?