0
我已經在索引0處存儲數據表,並且在列表中的索引1處存在int,現在我想將列表索引0轉換爲數據表。如何將其轉換爲數據表?列表索引轉換爲數據表
//Class Function
public List<object> Login(string A, string B)
{
DataTable dt = new DataTable();
xConn.Open();
SqlCommand xComm = new SqlCommand("Ulogin");
xComm.CommandType = CommandType.StoredProcedure;
xComm.Connection = xConn;
xComm.Parameters.AddWithValue("@Email", A);
xComm.Parameters.AddWithValue("@Pass", B);
int usercount = (Int32)xComm.ExecuteScalar();
xComm.ExecuteNonQuery();
new SqlDataAdapter(xComm).Fill(dt);
List<object> L = new List<object>();
L.Add(dt);
L.Add(usercount);
return L;
}
//Web Form
protected void Sub_Click(object sender, EventArgs e)
{
string Email = TextBox3.Text;
string Pass = TextBox4.Text;
List<object> L = d.Login(Email,Pass);
int I = Convert.ToInt32(L[1]);
if (I > 0)
{
//How does it convert here?
}
else
{
Response.Write("Incorrect Email Or Password");
}
}
'(數據表)L [0];'或'L [0]作爲DataTable' –
如果其始終兩個長度和索引0和1總是做同樣的工作,然後使用'Tuple'代替列表。降低代碼的複雜性。在這種情況下,你也不需要施放。 –
甚至超越使用元組,使用自定義類來表示數據。在這種情況下,「列表