This is a very cold Sunday - a day to stay indoors and ask for tips and solutions to my programming problems... and hopefully the experts are also staying home biding their time helping the likes of me...
I am using an unbound dataGridView which displays data retrieved from a table in an Sql database.
I use the code below to get the data from the table - it works fine.
My problem is that the code below resides on the form which has the dataGridView. In all other parts of the application I separated the Visual interface (the form) from code that saves and retrieve data in and out of the database by using a class which handle these tasks.
I am not able to do so with this part because I am using a dataSet as the data source form my dataGridView. I am new to datasets and dataTable and more used to the dataReader.
I am hoping you will show me how to create a class with a method that allows the dataGridView (which is on the form calss) to use the dataSet which will be in the newly created class
private void getDataForGrid()
con = new SqlConnection("Server=PC;Database=HelpDesk;integrated security=True");
SqlCommand comm = new SqlCommand("select ID, dDate as Date, tTime as Time,Name,Test,Phone,Remarks from Appointments where dDate=@dDate", con);
comm.Parameters.Add("dDate", SqlDbType.Date, 10, "dDate").Value = Convert.ToDateTime(this.txtDate.Text);
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
dataGridView1.DataSource = ds.Tables["Appointments"];