1
Everything all right? I’m new in C# and I’m stuck in a little problem with a project in Visual Studio:
I am developing a project with DAO standard (DATA ACCESS OBJETC). I have an interface responsible for the methods that will perform the persistence called Interfacedarso:
public interface InterfaceDAOCurso{
void adicionarCurso(Curso c);
List<Materia> pesquisarCurso(String curso);
}
And the class that implements this Daocurso interface:
public class DAOCurso : InterfaceDAOCurso{
public static String stringConexao = "Data Source=LOCAL-pc ;" +
"Initial Catalog=tccDataBase;" +
"Trusted_Connection=yes";
public DAOCurso()
{
//
// TODO: Add constructor logic here
//
}
public void adicionarCurso(Curso c)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = stringConexao;
String sql = "Insert into curso (id,nomeCurso,turno,sigla) values(" + c.getId() + ",'" + c.getNomeCurso() + "','" + c.getTurnoCurso() + "','" + c.getSigla() + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Dispose();
}
I would like to implement the List type method by returning a list with the amount of subjects related to this course. However, I am having trouble getting the list with Query output. (The problem is not the sql command). Is it possible to use result set? How would the implementation of this function?
Another thing that is still not very clear to me is how Table works in Asp and how I could popular this table with the list that will be returned from my function.
From now on, thank you very much!
I’m not sure I fully understand the question, you want to popular a list with the result of the command ?
– stringnome
I may have complicated a little rs. I want to popular a List with the results of a Select. And then use the populated list to fill a table with the data resulting from this select. Did you understand? In java I used the resultset but could not get a similar solution in C#. I am programming for the web and could be Table, gridView or any component of the type to pass the search results.
– Vítor Martins Borges
Vitor take a look at the answer I posted I believe this example will help you , I’m sorry for the delay .
– stringnome