ODBC adapter question?? What is wrong here?

M

max

I have a routine to load CBO's on the main form, which is below. In
this I check the reader for .HasRows and if this is FALSE I invoke the
routine to Add constants to the table. In the Add Constants rountine
I add two rows that are required, then let the user make any changes
they need via a datagrid. When I click update on the AddConstants
form the cmdUpdate_Click rountine executes and makes the changes to
the database. All this work up to here.

When I exit from the AddConstants and come back to the routine below
and execute the reader after the show dialog rd.HasRows is still
false. I can see the data in the table, the SQL statement is correct
and executs without and error, it's just that .HasRows doesn't go
TRUE. What am I doing wrong? Any ideas on how to change this to make
it work correctly???

Thanks,
--max

<<code below>>

Main.vb

Private Sub LoadCBOS(ByVal cboType As DataDescriptors.CBOsInUse,
ByVal cbo As ComboBox, ByVal cn As OdbcConnection)
Dim sSQL As String = "SELECT * FROM " & sCBOSelects(cboType) &
_
" ORDER BY " & sCBOSelects(cboType) & ".Order"
Dim sCMD As New OdbcCommand(sSQL, cn)
Dim rd As OdbcDataReader
Dim i As Integer = 0

'Create a collection for this CBO
colCBO = New Collection
Try
rd = sCMD.ExecuteReader()
While Not rd.HasRows
rd.Close()
Dim fAdd As New AddConstants
fAdd.ODBCConn = cn
fAdd.TblOfInterest = cboType
fAdd.ShowDialog()
rd = sCMD.ExecuteReader() 'every table gets at
least two entries
End While
....

AddConstats Form

Private Sub AddConstants_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim csPrevState As ConnectionState
lblChangeName.Text = gsTableTitles(m_tableType)
sSel = gsDB_SelStmts(m_tableType)

Try
csPrevState = m_odbcconn.State
If csPrevState = ConnectionState.Broken Then
_odbcconn.Open()
adapter.SelectCommand = New OdbcCommand(sSel, m_odbcconn)
adapter.Fill(ds)
If ds.Tables(0).Rows.Count = 0 Then
ds.Tables(0).Rows.Add(New Object() {"00", 1,
"Unitialized"})
ds.Tables(0).Rows.Add(New Object() {"01", 2, "Other"})
i = 1
End If
dgConstants.SetDataBinding(ds, "Table")
If csPrevState = ConnectionState.Closed Then
m_odbcconn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
i += 1
End Sub

Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdUpdate.Click
Dim dsChgs As DataSet
Dim dsCB As New OdbcCommandBuilder(adapter)

dsCB.QuotePrefix = "["
dsCB.QuoteSuffix = "]"

Try
dsChgs = ds.GetChanges()
dgConstants.SetDataBinding(dsChgs, "Table")
Dim i
i = adapter.Update(dsChgs)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top