列表索引转换为数据表

时间:2015-10-16 17:42:22

标签: c# asp.net

我已将数据表存储在索引0处,而int存储在List中的索引1处,现在我想将列表索引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");
        }

     }

1 个答案:

答案 0 :(得分:1)

怎么样:

DataTable table = (DataTable) L[0];

有关详细信息,请参阅:Casting and Type Conversions