This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Data; | |
| using System.Data.SqlClient; | |
| using DevExpress.XtraEditors; | |
| // connection string | |
| string connectionString = @"Server=.\SQLEXPRESS;Database=MyDatabase;Trusted_Connection=True;"; | |
| private void LoadComboBox() | |
| { | |
| using (SqlConnection conn = new SqlConnection(connectionString)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void ClearAllControls() | |
| { | |
| // Local recursive function to clear controls | |
| void ClearCollection(Control.ControlCollection controls) | |
| { | |
| foreach (Control ctrl in controls) | |
| { | |
| // Specific DevExpress controls | |
| if (ctrl is DevExpress.XtraEditors.ComboBoxEdit combo) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Όταν περιμένεις πολλές γραμμές: | |
| List<Product> products = new List<Product>(); | |
| using (SqlConnection conn = new SqlConnection(connectionString)) | |
| { | |
| string query = @"SELECT ProductId, Name, Price FROM Products WHERE Category = @Category"; | |
| using (SqlCommand cmd = new SqlCommand(query, conn)) | |
| { | |
| cmd.Parameters.AddWithValue("@Category", categoryName); | |
| conn.Open(); |