all groups > c# > february 2007 >
You're in the

c#

group:

how to specify which row is to be displayed?


how to specify which row is to be displayed? Edwin Smith
2/23/2007 6:04:43 PM
c#:
Hello:

I have a form which I would like to fill with data from one row of an ODBC
database table.

I have created the Table adapter and I have a query:

SELECT PATIENT.Name, PATIENT.address
FROM PATIENT
WHERE PatientID = ?

This gives me a GetDataBy(PatientID) method.

How can I then drag the controls onto the form and specify they be filled
with the row which is specified by PatientID?

There is also a Query that gets All Rows for a DataGridView in another form
which the drag and drop seems to default to such that I always get the first
row and not the row I specified programaticaly.

If I can't drag/drop then how do I change ordinary textboxes to be databound
by the GetDataBy(PatientID) query?

Thanks

Edwin

Re: how to specify which row is to be displayed? mangist NO[at]SPAM gmail.com
2/23/2007 8:15:28 PM
[quoted text, click to view]

Declare a DataSet. Fill the DataSet with data (use a
SqlDataAdapter). Bind a grid to the DataSet using gridView.DataSource
= myDataSet;. Add some text controls to your form. Set the data
binding properties to bind to your DataSet. The gridView control will
take care of the rest (i.e. the currencyManager).

myGridView.DataSource = myDataSet.Tables["Patient"];

txtPatientName.SetDataBinding (myDataSet.Tables["Patient"], "Name");
txtPatientAddress.SetDataBinding (myDataSet.Tables["Patient"],
"Address");

this should do it, every time you choose another patient in the grid,
the text controls will be updated appropriately.
Jon
Re: how to specify which row is to be displayed? Edwin Smith
2/25/2007 12:39:20 AM

[quoted text, click to view]

I have that much pretty well working. It was when I went to the second form
is where I was having a problem.

I discovered that when I would drag a field to the form VS2005 would create
a navigator for me that I could type in a PatientID and click the button to
get the row of data.

I took part of the code it generated and modified it to plug in the
PatientID passed from the other form and it works fine now. I had to do that
for each table adapter of which there were about 12 to get all of the info
for that patient ID.

Here's one of the 12 lines of code to fetch the row of data:

this.pATIENTSTableAdapter.FillByPatientID(this.patients.PATIENTS,
Convert.ToInt32(this.Tag));

Thanks for your help.

Edwin

AddThis Social Bookmark Button