Вот мой код:
Код: Выделить всё
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-PIERKI5\SQLEXPRESS;initial Catalog=LoginDb;integrated Security=True;");
string com = "Select UserID, taskName from Tasks";
SqlDataAdapter adpt = new SqlDataAdapter(com, con);
DataSet myDataSet = new DataSet();
adpt.Fill(myDataSet, "Tables");
DataTable myDataTable = myDataSet.Tables[0];
DataRow tempRow = null;
if(Session["UserID"] == )
{
foreach (DataRow tempRow_Variable in myDataTable.Rows)
{
tempRow = tempRow_Variable;
TasksListBox.Items.Add((tempRow["taskName"].ToString()));
}
}
}
Код: Выделить всё
protected void btnLogin_Click(object sender, EventArgs e)
{
Page.Validate();
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-PIERKI5\SQLEXPRESS;initial Catalog=LoginDb;integrated Security=True;");
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM tblUser WHERE UserName= '"+txtName.Text+"' AND Password= '"+txtPassword.Text+"' AND Usertype= '"+ DropDownList1.SelectedItem.ToString() + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
if (DropDownList1.SelectedIndex == 0) //admin
{
Session["username"] = txtName.Text.Trim();
Response.Redirect("Default_admin.aspx");
}
else if (DropDownList1.SelectedIndex == 1) //user
{
Session["username"] = txtName.Text.Trim();
Response.Redirect("Default_user.aspx");
}
}
Подробнее здесь: https://stackoverflow.com/questions/730 ... erid-match
Мобильная версия