I have a usercontrol called AddRow and a form called TimeSheet ,Timesheet has a save_btn event, on click of save_btn the value enter in usercontrol should be written to database,but I am not able to access the value from usercontrol
below is the code
public void save_btn_Click(object sender, EventArgs e)
{
SqlCommand cmdinsert = new SqlCommand("insert into TimeSheet (Project_Name ,Activity_Name,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday) values (@Project_Name,@Activity_Name,@Monday,@Tuesday,@Wednesday,@Thursday,@Friday,@Saturday,@Sunday) ", con);
cmdinsert.Parameters.AddWithValue("@Project_Name", add.project_cbox.SelectedIndex);
cmdinsert.Parameters.AddWithValue("@Activity_Name", activity_cb.SelectedIndex);
cmdinsert.Parameters.AddWithValue("@Monday", add.monday_txt_val);
cmdinsert.Parameters.AddWithValue("@Tuesday", add.tuesday_txt_val);
cmdinsert.Parameters.AddWithValue("@Wednesday", add.wednesday_txt.Text);
cmdinsert.Parameters.AddWithValue("@Thursday", add.thursday_txt.Text);
cmdinsert.Parameters.AddWithValue("@Friday", add.friday_txt.Text);
cmdinsert.Parameters.AddWithValue("@Saturday", add.saturday_txt.Text);
cmdinsert.Parameters.AddWithValue("@Sunday", add.sunday_txt.Text);
con.Open();
cmdinsert.ExecuteNonQuery();
con.Close();
}
this event is in timesheet but the value is empty string...I just cant access the value,is there a solution? this is window application
public string monday_txt_val
{
get
{
return monday_txt.Text;
}
set
{
monday_txt.Text = value;
}
}
monday_txt is a textbox that is created dynamically,after the value is entered ,but it is reading a empty string,despite me entering a value in textbox,when it is passed to form value of monday_txt is empty string,how to fix this?
only way I can think of accessing monday_txt is by creating a instance of AddRow in Timesheet..but When new instance is created I will not be able to get the value, kindly help