watt Posted February 28, 2006 at 09:35 PM Report Share #16031 Posted February 28, 2006 at 09:35 PM o que é que esta mal aqui SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=(local);" + "Initial Catalog=bd;" + "Integrated Security=SSPI;"; SqlCommand sqlComm = new SqlCommand("SELECT * FROM utilizador WHERE user=@user;", conn); sqlComm.Parameters.Add("@user", SqlDbType.VarChar); sqlComm.Parameters["@user"].Value = user.Text; conn.Open(); SqlDataReader rdr = sqlComm.ExecuteReader(); string valida = rdr.HasRows.ToString(); label1.Text = valida.ToString(); conn.Close(); Link to comment Share on other sites More sharing options...
pebat Posted February 28, 2006 at 10:54 PM Report Share #16047 Posted February 28, 2006 at 10:54 PM que erro e que te da ? Link to comment Share on other sites More sharing options...
watt Posted March 1, 2006 at 12:32 AM Author Report Share #16073 Posted March 1, 2006 at 12:32 AM não é dar erro ... no user se poser um nome igual ao da BD ele na label1 deveria dizer true... mas dis sp False Link to comment Share on other sites More sharing options...
wolf Posted March 1, 2006 at 02:21 PM Report Share #16137 Posted March 1, 2006 at 02:21 PM bem vamos la ver se percebi a tua duvida. o sql nao da erro nenhum mas deves ver que na string do sql tirar o ; antas das " pois isso fica assuciado ao comando e tu nao queres isso acho ru nem tive a ver se estou certo ou nao mas experimenta. mais de ersto nao vejo errro nenhum Link to comment Share on other sites More sharing options...
watt Posted March 2, 2006 at 02:12 AM Author Report Share #16310 Posted March 2, 2006 at 02:12 AM sem o ; faz o mesmo Link to comment Share on other sites More sharing options...
Bastos Posted April 7, 2006 at 03:30 PM Report Share #21311 Posted April 7, 2006 at 03:30 PM pq n utilizas SP(store procedures), sempre é mais fácil... esta é a minha opinião!! codigo com SP, SqlConnection dbLogin = new SqlConnection(ConfigurationSettings.AppSettings["Liga_BD"]); SqlDataAdapter spLogin = new SqlDataAdapter ("spLogin", dbLogin); spLogin.SelectCommand.CommandType = CommandType.StoredProcedure; SqlParameter paramUser = new SqlParameter("@username", SqlDbType.NVarChar, 20); paramUser.Value = txtUser.Text; spLogin.SelectCommand.Parameters.Add(paramUser); este código crias no ficheiro webconfig do teu projecto, assim sempre q kiseres ligar a BD, xamas 'Liga_BD', <appSettings> <add key="Liga_BD" value="server=SRV; database=Login; user id=root; password=pass"/> </appSettings> este codigo é pra VS C# 2003, e SQL server 2003; como n indicaste kal estas a utilizar... 😁 espero ter ajudado, fika bem... P.S.: aguardo resposta aki 😉 Link to comment Share on other sites More sharing options...
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