ado.net dataset and bindings

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I double click and item in a list box on a form that
contains the primary index value for a dataset. this
brings up a second form to display the row fields of the
dataset through databindings

The primary index value is made available to the second
form.


How do i make the second form display the row that
contains the primary index instead of the first row in
the dataset?

I've been unsuccessful in trying to pass the row value
or position of the dataset to the second form.

Any help would be appreciated.

thanks mike
 
Hello Mike


Sample code:

Dim MyEdit As New
UpdateAccountTypes(MyTable.Rows(Me.DataGrid1.CurrentCell.RowNumber))

MyEdit.ShowDialog()

Me.DataGrid1.Refresh()

Explanationof Code:

UpdateAccountTypes is a form that takes a DataRow as an argument to the
New() contstuctor

I get the currently selected row of the datagrid using:

MyTable.Rows(Me.DataGrid1.CurrentCell.RowNumber)

This should give you some insight into doing what you need


Ibrahim

(e-mail address removed)
 
Hi Mike,

Pass the primary key as a global variable by developing a globals class in a
module. Then search using the PK in a standard way. Below is an example of
using a PK to search a dataset/datatable:
Dim oconn As New SqlConnection("data source=d5z0071;initial
catalog=imc;integrated security=sspi;")

Dim ocmd As New SqlCommand("select * from evcodes", oconn)

Dim oda As New SqlDataAdapter(ocmd)

Dim ods As New DataSet("Event Codes")

Try

oconn.Open()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

oda.Fill(ods, "Event Codes")

Dim irow As DataRow

Dim colpk(0) As DataColumn

colpk(0) = ods.Tables(0).Columns("eventcd")

ods.Tables(0).PrimaryKey = colpk

irow = ods.Tables(0).Rows.Find("02") ' Mike - in this table the pk is a 2
char string column as I have

' need for only a few different kinds of events

If irow Is Nothing Then

MessageBox.Show("Not found")

Else

MessageBox.Show(irow("descrip"))

End If

oconn.Close()

You can also use a dataview to search when searching for non-PK cols.

HTH,

Bernie Yaeger
 
Back
Top