what is the use of hashtable? asp.net c#
Hi What is the use of hashtable? can i use to move record from database in click event of the button using hashtable? if yes then how possible? Thank You.
//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.T开发者_开发知识库oString(Convert.ToInt32(Session["counter"].ToString()) + 1);
getQuestion(myArray[z]);
}
else
{
RegisterStartupScript("myAlert", "<script>alert('Please select the option')</script>");
}
}
else
{
Response.Redirect("Default.aspx");
}
}
}
Add code in button click,as below
"; } }
If I am getting you corretly then you want something like this
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;
}
}
精彩评论