Hello R,
How do you expect Class1 instance to know value of a,b,c,d. What you should be doing in your code behind is
protected void Button1_Click(object sender, EventArgs e)
{
Class1 obj = new Class1();
obj.EmpId = Convert.ToInt32(txtEmpId.Text);
obj.EmpName = txtEmpName.Text;
obj.Salary = Convert.ToInt32(txtSalary.Text);
obj.City = txtCity.Text;
obj.Save();
}
And change your Class1 as
using System.Data.SqlClient;
public class Class1
{
private int _Event;
private int _EmpId;
private string _EmpName;
private int _Salary;
private string _City;
public int Event
{
get { return _Event; }
set { Event = value; }
}
public int EmpId
{
get { return _EmpId; }
set { EmpId = value; }
}
public string EmpName
{
get { return _EmpName; }
set { EmpName = value; }
}
public int Salary
{
get { return _Salary; }
set { Salary = value; }
}
public string City
{
get { return _City; }
set { City = value; }
}
public void Save()
{
SqlConnection connect = new SqlConnection();
SqlCommand command = new SqlCommand("YOUR INSERT QUERY GOES HERE");
command.Parameters.Add("@EmpId", SqlDbType.Int).Value = EmpId;
command.Parameters.Add("@Emp_name", SqlDbType.NVarChar).Value = EmpName;
command.Parameters.Add("@Salary", SqlDbType.Int).Value = Salary;
command.Parameters.Add("@City", SqlDbType.NVarChar).Value = City;
connect.Open();
command.ExecuteNonQuery();
command.Connection.Close();
}
}
Regards,