private void btnOKAddfunds_Click(object sender, EventArgs e) { frmFunds objfrmfundToAdd = new frmFunds(ThefrmMain); cmbFundNumber.Visible = false; //insert funds funds = new Fund(); funds.FundName = txtFundName.Text; if (string.IsNullOrEmpty(this.txtFundName.Text)) { throw new ArgumentNullException("fund name can't be null"); } else fundsData.insert(funds); //add funid in combobox DataTable dt3 = fundsData.FillcmbFundNumber(); cmbFundNumber.DisplayMember = "FundID"; this.cmbFundNumber.DataSource = dt3; this.Close(); try { // dt.Rows.Add(dataGridFunds.NewRowIndex,txtFundName.Text); // dataGridFunds.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Update(Fund oldFund,Fund newFund) { string ConnectionString = ConfigurationManager.ConnectionStrings[@"RecordKeeper.Properties.Settings.RecordkeeperConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(ConnectionString); try { connection.Open(); // int Primary_Field_Value = dataGridFunds[Column_Index, Row_Index].value.Tostring(); SqlCommand command = new SqlCommand("UPDATE[Recordkeeper].[dbo].[Fund] SET FundName=@FundName WHERE FundID=@FundID", connection); command.Parameters.AddWithValue("@FundName", newFund.FundName); command.Parameters.AddWithValue("@FundID", oldFund.FundNumber); command.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection != null) connection.Close(); } }
public void insert(Fund funds) { try { string cmdText = "INSERT INTO dbo.Fund(FundName) VALUES(@FundName)"; SqlCommand cmd = new SqlCommand(cmdText, connection); //cmd.Parameters.AddWithValue("@FundID", funds.FundNumber); cmd.Parameters.AddWithValue("@FundName", funds.FundName); connection.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if(connection!=null){ connection.Close(); } } }