I'm working in a smal project where I'm using userControl displayed within the main form. I'm using a Model class which allow access to database look like:
public void InsertRoute(Route route)
{
string routecode = route.RouteCode.ToString();
string vehiclecode = route.VehicleCode.ToString();
string firsstudentname = route.FirstStudentName.ToString();
using (SqlCommand cmd = new SqlCommand("InsertRoute2", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@RouteCode", routecode));
cmd.Parameters.Add(new SqlParameter("@VehicleCode", vehiclecode));
cmd.Parameters.Add(new SqlParameter("@FirstStudentName", firsstudentname));
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
then i have a user control called UCCreateRotue which has several textboxes and Button click Event handler :
private void btnCreateRoute_Click_1(object sender, EventArgs e)
{
UCRouteCreate form = new UCRouteCreate();
//DialogResult dialog = form.ShowDialog();
//if (dialog == DialogResult.OK)
//{
Route route = controller.CreateMovieFromText(form);
controller.InsertRoute(route);
//RefreshTable();
//}
}
then i have a Class called route as follow
class Route
{
private GlobalReach.UserControls.UCRouteCreate usrCon;
public string RouteCode
{
get { return usrCon.txtRouteCode.Text ;}
set { usrCon.txtRouteCode.Text = value ; }
}
}
then i have a method in controller as follow to perform the insert which is done through sproc
public Route CreateRouteFromText(UCRouteCreate form)
{
string routecode =form.txtRouteCode.Text.ToString();
string vehiclecode = form.txtVehicleCode.Text.ToString();
string firststudentname = form.txtFStudent.Text.ToString();
Route route = new Route();
return route;
}
my problem is when i click on the button click the code is working as i do have new rows inserted into my table but with empty value i.e the values are entered as nothing (if that make any sense) and the field that i dd not choose to fill entered as NULL value..? could you please advise on why when i enter values in my usrControl TextBox the value is not captured through my code.. thank you in advance