Hi everybody...
I want to show data in the data gridview placed in my form after getting data from my data access layer class through a class...
Here is my code in the data access layer class.
-
public class DBHandler
-
{
-
public List<Programs> GetAllPrograms()
-
{
-
-
SqlConnection con = new SqlConnection("Data source=ALIEN/SQLEXPRESS;Database=FinalProjectDB;Integrated security=True");
-
SqlCommand com = new SqlCommand();
-
com.CommandType = System.Data.CommandType.Text;
-
com.CommandText = "SELECT * FROM Programs";
-
com.Connection = con;
-
-
List<Programs> Program = new List<Programs>();
-
-
SqlDataReader reader;
-
-
con.Open();
-
-
reader = com.ExecuteReader();
-
-
if (reader.HasRows)
-
{
-
while (reader.Read())
-
{
-
Programs p = new Programs();
-
p.Id = Convert.ToInt32(reader["ProgramID"]);
-
p.Title1 = reader["Title"].ToString();
-
-
Program.Add(p);
-
}
-
-
}
-
-
con.Close();
-
-
return Program;
-
}
-
-
-
}
-
-
}
-
And the code in my form is.
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
DBHandler ObjDBHandler = new DBHandler();
-
-
dataGridView3.DataSource = ObjDBHandler.GetAllPrograms();
-
//I need code here to display Id and Name.
-
-
}
-
-
}
-
The confusion is in the portion of the program which i bold. here is a function naming GetAllPrograms getting values from the above mentioned class what i want is to show the Id and the Name in the gridview.
Does any one help me to sort out the problem...