osiris_z0r Posted May 6, 2009 at 06:20 PM Report #261917 Posted May 6, 2009 at 06:20 PM Help plz. 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 😁
Betovsky Posted May 6, 2009 at 07:42 PM Report #261932 Posted May 6, 2009 at 07:42 PM http://www.portugal-a-programar.pt/index.php?showtopic=27224 Mas o que é que se passa? Andam a copiar o código uns aos outros? Já agora nunca vai guardar porque o 'a' vai ser sempre igual a 1 "Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !" Sign on a computer system consultant's desk
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now