hi everyone i need ur help here is the problem i want to insert this values into my table at the same time (Member_ID,Interest_ID,Reference,date,interest_Recived ) at the end of every month then my code is look like this

private void Icalculater()
  {
    decimal x = Convert.ToDecimal(i_RateComboBox.Text);

    DateTime t = Convert.ToDateTime(this.fmonthtextBox.Text);
    DateTime v = Convert.ToDateTime(this.LmonthtextBox.Text);
    String text = String.Format("{0:MMM-yyyy} Interest", v);

    try
    {
      Adp.InsertCommand = new SqlCommand("insert into Received_Interest(Member_ID,Interest_Recived) select Member_ID,round(round((" + x + "/100/12),4)*sum(Amount_deposited),2)as I_R from Deposit_Statement where Deposit_Statement.Date between  '" + t + "' and '" + v + "' group by Member_ID", con);
      Adp.UpdateCommand = new SqlCommand("Update Received_Interest Set Interest_ID=@Interest_ID,Date=@Date,Reference=@Reference  ", con);
      Adp.UpdateCommand.Parameters.Add("@Interest_ID", SqlDbType.Int).Value = int.Parse(i_RateComboBox.SelectedValue.ToString());
      Adp.UpdateCommand.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Parse(dateTimePicker1.Text);
      Adp.UpdateCommand.Parameters.Add("@Reference", SqlDbType.NVarChar).Value = text;
      con.Open();
      Adp.InsertCommand.ExecuteNonQuery();
      Adp.UpdateCommand.ExecuteNonQuery();
      con.Close();
      MessageBox.Show("Successfully you Enter the Interest", "Successfully you Enter the Interest");


    }
    catch
    {
      Console.Beep();
      MessageBox.Show("Enter All the Information Correctly Please", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

the problem of this code is when i calculate the interest for the next month it also update the last month data

pls any one help me to edit my code the other thing if sum of deposit is less than 800 the interest is not calculated thanks in advance

To insert into more than one table at once try doing something like:

INSERT INTO (table1.coloumn1, table.column2) VALUE (value1, value2);

might not be exactly what you want but you'll probably want something along those lines to insert into multiple tables in 1 statement.

i want to insert all the values into one table not multiple table

i figure out the answer
the problem is on line 12 so i give where clues in that line where Interest_ID is null

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.