this is code in datalayer
public class Student
{
SqlConnection connection = new SqlConnection("Data Source...............");
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
public DataTable Read()
{
connection.Open();
cmd.CommandText = "SELECT * from Student";
SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, connection);
da.Fill(ds);
//cmd.ExecuteReader();
connection.Close();
dt = ds.Tables[0];
return dt;
}
public void Add(string studentName, string FatherName, string ClassName )
{
cmd.CommandText = "INSERT INTO Student (StudentName,FatherName,ClassName) VALUES (@StudentName, @FatherName,@ClassName )";
cmd.Parameters.AddWithValue("@StudentName", studentName);
cmd.Parameters.AddWithValue("@FatherName", FatherName);
//cmd.Parameters.AddWithValue("@DateOfBirth", DateofBirth);
cmd.Parameters.AddWithValue("@ClassName", ClassName);
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
}
here i dont wana to use parameter please alternative??????
public void Update(string studentName, string FatherName, string ClassName)
{
cmd.CommandText = "Update Student SET FatherName=@FatherName,ClassName=@ClassName";
cmd.Parameters.AddWithValue("@StudentName", studentName);
cmd.Parameters.AddWithValue("@FatherName", FatherName);
cmd.Parameters.AddWithValue("@ClassName", ClassName);
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
}
public DataTable Clear()
{
SqlCommand cmd = new SqlCommand("DELETE FROM Student", connection);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
return dt;
}
this code in bussinesslayer
here i also dnt wanna use parameter plese tell me alternative
public class BClass
{
public DataTable GetStudentAccount()
{
{
Student stu = new Student();
return stu.Read();
}
}
public DataTable RemoveStudent()
{
{
Student stu = new Student();
return stu.Clear();
}
}
public bool save()
{
Student stu = new Student();
stu.Add("asim", "ali", "5th");
return true;
}
public bool UpdateStudent()
{
Student stu = new Student();
stu.Update("asim", "fazal", "6th");
return true;
}
}
<<big>b>this is behine the presentation layer
kindly tell me alternative way where i dnt wanna use parameter and not entityframework and also use just 3 layer architecture
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
BClass p = new BClass();
this.dataGridView2.DataSource = p.GetStudentAccount();
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
BClass a = new BClass();
this.dataGridView2.DataSource = a.save();
}
private void button4_Click(object sender, EventArgs e)
{
BClass u = new BClass();
this.dataGridView2.DataSource = u.UpdateStudent();
}
private void button5_Click(object sender, EventArgs e)
{
BClass d = new BClass();
this.dataGridView2.DataSource = d.RemoveStudent();
}
}