leoretorico Posted August 1, 2012 at 09:56 PM Report Share #471245 Posted August 1, 2012 at 09:56 PM Boa noite amigos,sou novo em c# e normalmente para conectar com postgreSql,Acess e sqlServer eu uso o código direto no form load e nos buttons(delete,update e insert) Gostaria muito que alguém pudesse me indicar um tutorial,projeto para download ou me mostrar um exemplo de uma classe de conexão entre c# e algum banco de dados. Pois com CLASS o código fica mais organizado... obrigado Link to comment Share on other sites More sharing options...
Will_dvp Posted August 2, 2012 at 03:45 AM Report Share #471258 Posted August 2, 2012 at 03:45 AM Amigo, Pelo que esta falando acredito que estás a usar um linguagem orientada à objetos de forma procedural, portanto antes de pedir um exemplo de classe que implementa uma conexão à database, seria interessante estudar orientação à objetos. Mas aqui tem um exemplo ( meio bagunçado, mas da para entender ): http://www.antaresinfo.blogspot.com.br/2008/08/criando-uma-classe-de-conexo-no-c.html Link to comment Share on other sites More sharing options...
leoretorico Posted August 6, 2012 at 10:15 PM Author Report Share #471624 Posted August 6, 2012 at 10:15 PM Sim ...deu para entender! você ou a galera do forum teriam mais exemplos?? preciso aprofundar mais. Obrigado! Link to comment Share on other sites More sharing options...
pikax Posted August 6, 2012 at 10:22 PM Report Share #471625 Posted August 6, 2012 at 10:22 PM Podes usar odbc, so' nao sei se funciona com postgre Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
leoretorico Posted August 7, 2012 at 12:31 AM Author Report Share #471628 Posted August 7, 2012 at 12:31 AM como eu devo implementar um select(select * from tbl_links) no código abaixo? e gostaria de saber como posso no form load informa o estado da conexão ! ex messagebox.show=" conexão "+connection.state using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; namespace RHSever { class Connection { public static SqlConnection conexao = new SqlConnection(); public static void AbrirConexao() { conexao.ConnectionString = @"Server=Dta-PC;Database=DataLink;UID=Leo;PWD=******"; conexao.Open(); } public static void FecharConexao() { if (conexao.State == ConnectionState.Open) { conexao.Close(); conexao.Dispose(); } } public static void ExecutarComando(string textoComando) { if (conexao.State != ConnectionState.Open) { AbrirConexao(); } SqlCommand comando = new SqlCommand (); comando.CommandText = textoComando; comando.Connection = conexao; int registrosAfetados = comando.ExecuteNonQuery(); } public static SqlDataReader SelecionarRegistros(string textoComando) { if (conexao.State != ConnectionState.Open) { AbrirConexao(); } SqlCommand comando = new SqlCommand () ; comando.CommandText = textoComando; comando.Connection = conexao; return comando.ExecuteReader(); } public static SqlDataReader SelecionarUmRegistro(string textoComando) { if (conexao.State != ConnectionState.Open) { AbrirConexao(); } SqlCommand comando = new SqlCommand(); comando.CommandText = textoComando; comando.Connection = conexao; return (SqlDataReader)comando.ExecuteScalar(); } } } 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