在这里,我试图从 tblUser 中检索用户的全名,用户名也存在于 tblUser 中,并在文本框中显示它。但它显示错误列 'FullName' 不属于表,即使列 FullName 和 UserName 存在于表中。使用的代码
<asp:TextBox ID="txttfullname" CssClass="form-control" runat="server"></asp:TextBox>
后面的代码
DataTable dc = ojc.GetUser(lblusername.Text);
if (dc.Rows.Count > 0)
{
txttfullname.Text = dt.Rows[0]["FullName"].ToString();
}
public DataTable GetUser(string UserName)
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myconnection"].ConnectionString);
string sql = "select *from tblUser where UserName=@UserName";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@UserName", UserName);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
这部分是对的还是错字?
DataTable dc = ojc.GetUser(lblusername.Text);
if (dc.Rows.Count > 0)
{
txttfullname.Text = dt.Rows[0]["FullName"].ToString();
}
获取 Datatabledc
并与dt
绑定?
另一个问题
lblusername.Text
和dc
是否有值,您是否进行了调试和检查?
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(11条)