private void Insert(CategoryUi categoryUi) { try { // sqlConnection.Open(); commandString = @"INSERT INTO CategoryUi (Name) VALUES ('" + categoryUi.Name + "')"; sqlCommand = new SqlCommand(commandString, sqlConnection); int isExecuted; isExecuted = sqlCommand.ExecuteNonQuery(); if (isExecuted > 0) { MessageBox.Show("Saved!!"); } else { MessageBox.Show("Not Saved!!"); } // sqlConnection.Close(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void SaveButton_Click(object sender, EventArgs e) { CategoryUi categoryUi = new CategoryUi(); categoryUi.Name = CategorySetupTextBox.Text; Insert(categoryUi); }
private void CategoryUi_Load(object sender, EventArgs e) { CategoryUi categoryUi = new CategoryUi(); categoryUi.Name = CategorySetupTextBox.Text; Show(categoryUi); }
private void Show(CategoryUi categoryUi) { sqlConnection.Open(); // commandString = @"SELECT * FROM CategoryUi"; sqlCommand = new SqlCommand(commandString, sqlConnection); // SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); DataTable dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); if (dataTable.Rows.Count > 0) { CategorySetupDataGridView.DataSource = dataTable; } // sqlConnection.Close(); }
private void button1_Click(object sender, EventArgs e) { CategoryUi categorySetupUi = new CategoryUi(); categorySetupUi.Show(); }