James

James

  • NA
  • 3
  • 0

Populating a datagrid on a Windows form

Mar 29 2006 10:57 AM
Hi,

I'm fine using asp.net and ado.net  on the web app side of things. But I have just started learning about Windows applications and nothing seems to work! Just trying to populate a simple datagrid now seems impossible. There now does not appear to be the .DataBind or .DataKeyField methods??
My code is as follows:

private void button1_Click_1(object sender, System.EventArgs e)

{

SqlConnection myConnection = new SqlConnection ();

myConnection.ConnectionString = "server=myserver.com;database=myName;uid=sa;pwd=pwd3";

SqlCommand cmdDisplayStudent = new SqlCommand ("DisplayStudentsSingleCol",myConnection);

cmdDisplayStudent.CommandType = CommandType.StoredProcedure;

SqlDataAdapter myAdapter = new SqlDataAdapter ();

DataSet ds = new DataSet();

myConnection.Open();

myAdapter.Fill(ds);

this.dataGrid1.DataSource = ds;

this.dataGrid1.DataMember = "StudentID";

}

But how do I finish it off?  Can anyone please help?

Many thanks,
James


Answers (2)