Student Class Properties:
class student
{
public int s_id { get; set; }
public string sname { get; set; }
public string sfname { get; set; }
public string sgender { get; set; }
public string saddress { get; set; }
public string sdate { get; set; }
public string sfk { get; set; }
}
Method of Data Insertion
public string insert_srecord(student s)
{
string msg = " ";
SqlConnection conn = new SqlConnection(connstring);
try
{
SqlCommand cmd = new SqlCommand("insert_student", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@std_name", SqlDbType.NVarChar, 20).Value = s.sname;
cmd.Parameters.Add("@std_fname", SqlDbType.NVarChar, 20).Value = s.sfname;
cmd.Parameters.Add("@std_gender", SqlDbType.NVarChar, 20).Value = s.sgender;
cmd.Parameters.Add("@std_address", SqlDbType.NVarChar, 100).Value = s.saddress;
cmd.Parameters.Add("@std_admissiondate", SqlDbType.NVarChar, 20).Value = s.sdate;
cmd.Parameters.Add("@std_ad_fk_id", SqlDbType.NVarChar, 20).Value = s.sfk;
conn.Open();
cmd.ExecuteNonQuery();
msg = "data successfully inserted!";
}
catch (Exception)
{
msg = "data is not successfully inserted!";
}
finally
{
conn.Close();
}
return msg;
} //method end......................