Right, maybe it is better to have all the code in here, just in case there is something I'm missing.
So here is the Home.aspx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Home : System.Web.UI.Page
{
private int expenseID;//expense string can be rent, car, bills, food as integer so as 1,2,3,4
private SqlCommand sqlCmd;
private SqlConnection hookUp;
private string strInsert;
private string radioButtonId;
private SqlDataReader reader;
//private int storedInt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {//returns false the first time the page is displayed true when redisplayed
initForm();
}
}
private void initForm() {
amount.Visible = false;//hide amount info on page load
rent.Checked = false;//unselect all radio buttons
car.Checked = false;
bills.Checked = false;
food.Checked = false;
radioButtonID.Value = "";//empty hidden field
//System.Diagnostics.Debug.WriteLine("oh oh oh");
}
protected void CheckedChanged(object sender, EventArgs e)
{
amount.Visible = true;//showamount info on page load
/*find out the id of the selected button*/
RadioButton buttonId = sender as RadioButton;//cast sender as button
// radioButtonID.Text = buttonId.ID;//select the ID
radioButtonId = radioButtonID.Value = buttonId.ID;//select the ID
switch (radioButtonId) {
case "rent":
expenseID = 1;
break;
case "car":
expenseID = 2;
break;
case "bills":
expenseID = 3;
break;
case "food":
expenseID = 4;
break;
}
//TO REMOVE
//outputTxt.Text = DateTime.Now.ToString("dd/MM/yyyy");
// outputTxt.Text = Convert.ToString(expenseID);
}
protected void submitForm(object sender, EventArgs e){
hookUp = new SqlConnection("Server=localhost\\SqlExpress;Database=Applications;" + "Integrated Security=True");
strInsert = "INSERT INTO expenses(Date,ExpenseId,Cost,Comment) VALUES (@date,@expenseid,@cost,@comment)";
sqlCmd = new SqlCommand(strInsert, hookUp);
// sqlCmd.Parameters.Add("@date", …