exception has been thrown by the target of an invocation
Estou seguindo o curso de Multitier do Guinther, e estou encontrando o seguinte problema no UPDATE: exception has been thrown by the target of an invocation
Alguém poderia dar uma luz???
SEGUE ABAIXO A CLASSE:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
public class Gerenciador
{
private string ConStr = @´Data Source=Fernanda_TI\SQLEXPRESS;Initial Catalog=Gerenciador;Integrated Security=True´;
public DataSet Select()
{
SqlConnection con = new SqlConnection(ConStr);
string SQL = ´select * from Modulo´;
SqlCommand cmd = new SqlCommand(SQL, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public void Update(int ID_Modulo, string Nome_Modulo)
{
SqlConnection con = new SqlConnection(ConStr);
string SQL = ´update Modulo set Nome_Modulo=@Nome_Modulo where ID_Modulo=@ID_Modulo´;
SqlCommand cmd = new SqlCommand(SQL,con);
cmd.Parameters.AddWithValue(´@Nome_Modulo´, Nome_Modulo);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Alguém poderia dar uma luz???
SEGUE ABAIXO A CLASSE:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
public class Gerenciador
{
private string ConStr = @´Data Source=Fernanda_TI\SQLEXPRESS;Initial Catalog=Gerenciador;Integrated Security=True´;
public DataSet Select()
{
SqlConnection con = new SqlConnection(ConStr);
string SQL = ´select * from Modulo´;
SqlCommand cmd = new SqlCommand(SQL, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public void Update(int ID_Modulo, string Nome_Modulo)
{
SqlConnection con = new SqlConnection(ConStr);
string SQL = ´update Modulo set Nome_Modulo=@Nome_Modulo where ID_Modulo=@ID_Modulo´;
SqlCommand cmd = new SqlCommand(SQL,con);
cmd.Parameters.AddWithValue(´@Nome_Modulo´, Nome_Modulo);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Dotnet
Curtidas 0
Respostas
Ricardo Silva
15/07/2008
Ola...
tenta abrir a conexão antes referenciala ao SqlCommand
ve se da certo...
na duvida soh posta
tenta abrir a conexão antes referenciala ao SqlCommand
public DataSet Select(){ SqlConnection con = new SqlConnection(ConStr); string SQL = "select * from Modulo"; con.Open(); SqlCommand cmd = new SqlCommand(SQL, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); return ds; } public void Update(int ID_Modulo, string Nome_Modulo){ SqlConnection con = new SqlConnection(ConStr); string SQL = "update Modulo set Nome_Modulo=@Nome_Modulo where ID_Modulo=@ID_Modulo"; con.Open(); SqlCommand cmd = new SqlCommand(SQL,con); cmd.Parameters.AddWithValue("@Nome_Modulo", Nome_Modulo); cmd.ExecuteNonQuery(); con.Close(); }
ve se da certo...
na duvida soh posta
GOSTEI 0
Ricardo Silva
15/07/2008
ah otra coisa..
ficou faltando adicionar mais um parametro no upDate
na duvida soh posta
ficou faltando adicionar mais um parametro no upDate
cmd.Parameters.AddWithValue("@ID_Modulo", Nome_Modulo)
na duvida soh posta
GOSTEI 0
Ricardo Silva
15/07/2008
fernanda...
eai.. ja resolveu seu problema???
com o select e UpDate
eai.. ja resolveu seu problema???
com o select e UpDate
GOSTEI 0
Dotnet
15/07/2008
Sim já resolvi , muito obrigada
GOSTEI 0