none
add dataa to local database using c sharp RRS feed

  • General discussion

  • I'm developing a desktop application using c sharp and sql server, now i would like to perform add operation but i have probelm how to connect data to my local DB so any help

    thanks

    Thursday, August 4, 2011 1:53 PM

All replies

  • Hi
    Try this
     <pre>string _DB_CS = @"Server=SERVER_NAME\SQLEXPRESS;database=DATABASE_NAME;uid=USER_NAME;pwd=PASSWORD;Pooling=False";
                SqlConnection ligacao = new SqlConnection();
              
    
                ligacao.ConnectionString = _DB_CS;
                   
                ligacao.Open();
                SqlCommand comando = new SqlCommand();
                SqlDataAdapter adaptador;
                comando.Connection = ligacao;
                          
                comando.CommandText = "INSERT INTO YOUR_TABLE_NAME (FIELD1,FIELD2) VALUES ('VALUE1','VALUE2');";          
    
                adaptador = new SqlDataAdapter(comando);
                adaptador.SelectCommand.ExecuteNonQuery();
                ligacao.Close();
    

    Hope this help you to understand. Vote if helpful please and Mark as answer too, Thanks

    MCP
    Thursday, November 10, 2011 11:40 AM