【发布时间】:2016-08-30 05:40:36
【问题描述】:
我正在尝试根据 CustomerID 从数据库中检索和显示用户数据。执行时出现上述错误。
这是我显示数据的代码。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int customerID = Convert.ToInt32(Session["CustomerID"]);
MyProfileGridView.DataSource = CustomerBL.GetCustomer(customerID);
MyProfileGridView.DataBind();
}
}
获取客户方法代码:
public static Customer GetCustomer(int customerID)
{
Customer customer = new Customer();
string query = "SELECT * FROM [Customers] WHERE [CustomerID] = @CustomerID";
SqlCommand cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue("@CustomerID", SqlDbType.Text).Value = customerID;
DataTable dt = DbUtility.GetRecordsInDataTable(cmd);
if (dt.Rows.Count > 0)
{
customer.CustomerID = Convert.ToInt32(dt.Rows[0]["CustomerID"]);
customer.LoginID = dt.Rows[0]["LoginID"].ToString();
customer.Password = dt.Rows[0]["Password"].ToString();
customer.CustomerName = dt.Rows[0]["CustomerName"].ToString();
customer.ShopName = dt.Rows[0]["ShopName"].ToString();
customer.Address = dt.Rows[0]["Address"].ToString();
customer.Mobile1 = dt.Rows[0]["Mobile1"].ToString();
customer.Mobile2 = dt.Rows[0]["Mobile2"].ToString();
customer.ReferenceNumber = dt.Rows[0]["ReferenceNumber"].ToString();
customer.SignUpDate = Convert.ToDateTime(dt.Rows[0]["SignUpDate"]);
customer.Enabled = Convert.ToBoolean(dt.Rows[0]["Enabled"]);
return customer;
}
else
{
return null;
}
}
用户注册页面代码:
protected void Page_Load(object sender, EventArgs e)
{
int customerID;
if (!Page.IsPostBack)
{
if (Request.QueryString["CustomerID"] != null)
{
customerID = Convert.ToInt32(Request.QueryString["CustomerID"]);
Customer customer = CustomerBL.GetCustomer(customerID);
if (customer != null)
{
LoginIdLabel.Text = customer.LoginID;
PasswordLabel.Text = customer.Password;
}
}
}
}
错误 8 无法将类型 'System.Collections.Generic.List' 隐式转换为 '******.Entities.Customer' C:\Users*** **\桌面\新文件夹*******\UserSignUpSuccess.aspx.cs 25 41 ******
请帮我解决这个问题
【问题讨论】: