sYnced Posted May 23, 2012 at 01:30 PM Report #457596 Posted May 23, 2012 at 01:30 PM private static string cs = "Data Source=Helder-PC\\SQLEXPRESS;Initial Catalog=dbGestaoLiga;Integrated Security=True"; public static string InsereEquipa(string nome, string cidade, string divisao, string serie) { SqlConnection cn = null; SqlCommand inserir = null; try { cn = new SqlConnection(cs); inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "',"+divisao+"','"+ serie+"')"); cn.Open(); inserir.ExecuteNonQuery(); } Dá me erro na ExecuteNonQuery alguém me pode ajudar ?
Caça Posted May 23, 2012 at 01:39 PM Report #457601 Posted May 23, 2012 at 01:39 PM (edited) Que erro? Troca a tua query por esta inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "','"+divisao+"','"+ serie+"')"); Edited May 23, 2012 at 01:39 PM by Caça Pedro Martins Não respondo a duvidas por PM
sYnced Posted May 23, 2012 at 01:43 PM Author Report #457607 Posted May 23, 2012 at 01:43 PM Que erro? Troca a tua query por esta inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "','"+divisao+"','"+ serie+"')"); CitarExecuteNonQuery: Connection property has not been initialized. Continua o mesmo erro!
Rechousa Posted May 23, 2012 at 01:58 PM Report #457612 Posted May 23, 2012 at 01:58 PM (edited) Muda a linha para: inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "','"+divisao+"','"+ serie+"')", cn); Quando crias um SqlCommand tens de o associar à tua SqlConnection. Edited May 23, 2012 at 01:58 PM by Rechousa Pedro Martins Sharing is Knowledge! http://www.linkedin.com/in/rechousa
sYnced Posted May 23, 2012 at 02:44 PM Author Report #457633 Posted May 23, 2012 at 02:44 PM Muda a linha para: inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "','"+divisao+"','"+ serie+"')", cn); Quando crias um SqlCommand tens de o associar à tua SqlConnection. Muito Obrigado 🙂
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