Jump to content

Recommended Posts

Posted

Help plz. :wallbash:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebApplication1
{

    public partial class _Default : System.Web.UI.Page
    {

        int a;


        protected void Button1_Click(object sender, EventArgs e)
        {

        string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\escola.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            SqlConnection sqlconn = new SqlConnection(connectionString);
            sqlconn.Open();
            SqlCommand comm = new SqlCommand("Select count(*) From utilizadores Where username = @utilizador And password = @password", sqlconn);

            comm.Parameters.Add("@utilizador", SqlDbType.NVarChar).Value = TextBox1.Text;
            comm.Parameters.Add("@password", SqlDbType.NVarChar).Value = TextBox2.Text;
          int i = (int)comm.ExecuteScalar();

            // Se i for maior que zero é porque achou o usuario/senha
            if (i > 0)
            {
                Lbl.Text = ("Senha correcta");
                            a = 0;
            }
       else
                Lbl.Text = ("Senha ou utilizador errado");
            a = 1;
            sqlconn.Close();


            if (a == 0)
            {

                //guarda, pois o user é correcto

                try
                {

                    string connectionString2 = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\escola.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

                    SqlConnection conn1 = new SqlConnection(connectionString2);
                    conn1.Open();
                   SqlCommand cmd1 = new SqlCommand("UPDATE utilizadores SET lastlogin = @lastlogin, lastip = @lastip where username = @utilizador", conn1);

                    cmd1.Parameters.Add("@utilizador", SqlDbType.NVarChar).Value = TextBox1.Text;
                    cmd1.Parameters.Add("@lastlogin", SqlDbType.NVarChar).Value = lbldate.Text;
                    cmd1.Parameters.Add("@lastip", SqlDbType.NVarChar).Value = lblip.Text;
                    cmd1.ExecuteNonQuery();
                    conn1.Close();

                }
                finally { }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string result = String.Empty;
            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }

            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }


            lblip.Text = (result);


            DateTime x = DateTime.Now;

            lbldate.Text = (Convert.ToString(x));
        }





    }

}

Assim muito rapidinho, eu quero que ele envie os dados que estão nas labels

lblip e lbldate para os campos lastip e lastlogin da tabela utilizador .

E ele não envia nada --'

agradecia ajuda  😁

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.