Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datatable and primary key problem

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
I create a datatable with a primary key and it works until I do the sorting from the dataview and refill the datatable. At which time I start getting message when I try to make changes to the table that Table does not have a primary key.

Setting primary key

mdtComp = New Data.DataTable
Dim dsProcs As Data.DataSet = New Data.DataSet
With dsProcs
.Tables.Add("Comp")
.Tables("Comp").Columns.Add("Model", System.Type.GetType("System.String"))
End With
columns(0) = dsProcs.Tables("Comp").Columns("Model")
dsProcs.Tables("Comp").PrimaryKey = columns
mdtComp = dsProcs.Tables("Comp")
mdvComp = New Data.DataView(mdtComp)

After I do the below I no longer have the primary key.

If Trim(txtFilter.Text) <> "" Then
iGot = txtFilter.Text.IndexOf("%")
If iGot > 0 Then
strSQL = "Model Like '" + txtFilter.Text + "'"
Else
strSQL = "Model Like '" + txtFilter.Text + "%'"
End If
Else
strSQL = "Model%"
End If

mdvComp.RowFilter = strSQL
mdtComp = mdvComp.ToTable
dgdComp.Rows.Clear()
LoadGrid()

Any suggestions on how reset primary key?

Thanks

Louie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top