您如何根据当前登录用户实际显示从数据库中检索到的数据?我使用了这种方法,但它实际上不起作用。我哪里出错了?
我的 .cs 代码:
int selectedRow = GridView1.SelectedIndex;
GridViewRow row = GridView1.Rows[selectedRow];
int UserId = Convert.ToInt32(row.Cells[0].Text);
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
string strConnectionString = ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString1"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
string strCommandText = "SELECT date, starttime, endtime, planner FROM bookings WHERE UserId =@UserId";
SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
myConnect.Open();
SqlDataReader reader = cmd.ExecuteReader();
cmd.Parameters.AddWithValue("@UserId", UserId);
reader.Close();
myConnect.Close();