i need help here(my school project- UNIVERSITY HOSTEL ALLOCATION PORTAL): i want to load table with data from database. the table will contain FullName,RegNumber,Sex,Level,Department,Faculty,Session from database(StudentData) where the RegNumber match. I use table.Load(Reader) ie "result2.Load(dr)". the problem is that it works atimes; other times it give error:> "THAT I SHOULD AVOID INFINIT LOOP". here is the two methods in ALLOCATION.CS that give this error:
C#
voidMalestudent()
{
using (DataTable dt2 = LookupUser2(txtRegNumber.Text))
{
if (dt2.Rows.Count == 0)
{
messagebox.show(" profile is not updated")
return;
}
else
{
// renaming the items retreived to be passed to another methodstring R_Number = Convert.ToString(dt2.Rows[0]["RegNumber"]);
string strname = Convert.ToString(dt2.Rows[0]["FullName"]);
string strsx = Convert.ToString(dt2.Rows[0]["Sex"]);
string strlevel = Convert.ToString(dt2.Rows[0]["Level"]);
string strdpt = Convert.ToString(dt2.Rows[0]["Department"]);
string strfact = Convert.ToString(dt2.Rows[0]["Faculty"]);
string strsess = Convert.ToString(dt2.Rows[0]["Session"]);
.
.
.
}
privatestatic DataTable LookupUser2(string RegNumber)
{
// where i am looking into dbs in search of where RegNumber exist.// ERROR COMES FROM HEREstring connStr = ConfigurationManager.ConnectionStrings["SchooldataConnectionString1"].ConnectionString;
conststring query = "SELECT FullName,RegNumber,Sex,Level,Department,Faculty,Session FROM StudentData(NOLOCK) Where RegNumber = @RegNumber";
DataTable result2 = new DataTable();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add("@RegNumber", SqlDbType.VarChar).Value = RegNumber;
using (SqlDataReader dr = cmd.ExecuteReader())
{
result2.Load(dr);
}
}
}
return result2;
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
1 short reply
Suthish NairRank #93 · 22.6K pointsPosted Oct 30, 2010, 10:18 AM EDT
1 short reply
Suthish NairRank #93 · 22.6K pointsPosted Oct 30, 2010, 10:18 AM EDT