我想返回一个应该包含一个字符串的数据表,在返回一个数据表时手动添加一个字符串,下面是我正在使用的代码:
static public DataTable GetInfoByCode(string code, string user)
{
string sql = "SELECT aspnet_Users.UserName, " +
"Code.dateUsed" +
"FROM aspnet_Membership INNER JOIN" +
"aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId INNER JOIN"+
"rAccessCode ON aspnet_Users.UserId = rAccessCode.userID INNER JOIN"+
"Code ON rAccessCode.CodeID = Code.accessCodeID"+
"WHERE (Code.accessCode = code)";
MembershipUser userPass = Membership.GetUser(user);
string password = userPass.GetPassword();
SqlDataAdapter da = new SqlDataAdapter(sql, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt; //want to return password field in the dt so that i can link datasource with datagridview and show password and username in gridview
}
我想在 dt 中添加密码,以便在 datagrid 视图中检索密码字段,例如:
<asp:GridView ID="gvList" runat="server" >
<Columns>
<asp:BoundField DataField="UserName" ReadOnly="True" HeaderText="Username" />
<asp:BoundField DataField="password" ReadOnly="True" HeaderText="Password" />
</Columns>
</asp:GridView>