Jump to content

Recommended Posts

Posted
    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 ?

Posted (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 by Caça

Pedro Martins

Não respondo a duvidas por PM

Posted

Que erro?

Troca a tua query por esta

inserir = new SqlCommand("INSERT into Equipas(Nome, Cidade, Divisao, Serie) values ('"+ nome + "','"+ cidade + "','"+divisao+"','"+ serie+"')");

Citar

ExecuteNonQuery: Connection property has not been initialized.

Continua o mesmo erro!

Posted

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 🙂

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.