Asp.net 显示当前登录用户的记录
我想显示当前登录用户的记录。我可以显示记录,但它会显示已提交给系统的所有记录。我想要基于谁向数据库提交信息的记录 这是我希望从中显示想法的页面代码Asp.net 显示当前登录用户的记录,asp.net,Asp.net,我想显示当前登录用户的记录。我可以显示记录,但它会显示已提交给系统的所有记录。我想要基于谁向数据库提交信息的记录 这是我希望从中显示想法的页面代码 // CONNECT TO THE DB SqlConnection sqlCon = new SqlConnection(@"Data Source=ICS-40-JBONEY;Initial Catalog=TTXIdeaPortal;Integrated Security=True");
// CONNECT TO THE DB
SqlConnection sqlCon = new SqlConnection(@"Data Source=ICS-40-JBONEY;Initial Catalog=TTXIdeaPortal;Integrated Security=True");
sqlCon.Open();
//CREATE A COMMAND
int userid = Convert.ToInt32(Session["UserCookie"]);
//SqlCommand sqlcmd = new SqlCommand("SELECT [IdeaTitle], [IdeaDescription], [How], [Why], [Category] FROM [dbo].[EmployeeIdeas]");
SqlCommand sqlcmd = new SqlCommand("ustpGetEmployeeIdeas");
//SqlCommand sqlcmd = new SqlCommand("SELECT * from EmployeeIdeas where EloginID = ");
//sqlcmd.CommandType = CommandType.Text = "SELECT * FROM list where user_id = " + userid + "";
sqlcmd.CommandType = CommandType.Text;
sqlcmd.Connection = sqlCon;
string ideaTitle = "";
string ideaDescription1 = "";
string how1 = "";
string why1 = "";
//READ FROM DB
SqlDataReader reader = sqlcmd.ExecuteReader();
while (reader.Read())
{
ideaTitle += reader["IdeaTitle"].ToString();
ideaDescription1 += reader["IdeaDescription"].ToString();
how1 += reader["How"].ToString();
why1 += reader["Why"].ToString();
}
sqlCon.Close();
Label1.Text = ideaTitle;
Label2.Text = ideaDescription1;
Label3.Text = how1;
Label4.Text = why1;
}
}
}
看起来您没有向存储过程传递任何参数,因此它没有任何限制结果的方法。这是我的过程,我正在使用SqlCommand sqlcmd=new-SqlCommand(“从[dbo].[EmployeeIdeas]中选择[IdeaTitle],[IdeaDescription],[How],[Why],[Category];我首先明确指出如何根据当前用户限制记录您是否将用户id存储在[EmployeeIdeas]中?如果不是,这可能是不可能的。