For Loop

G

Guest

hey guys, for so long i've been using the Server Explorer to make the connection, config
the adapter and the dataset (just like i was taught in school), but that's not really the real world.
so, i started doing this all in code, which is great.
but, it means that the table, columns arent really known until runtime.
now, i have no problem filling a datagrid, HOWEVER a simple little for loop like:

Dim info As String
Dim i as Integer

For i = 0 To (Ds.Cont_Payroll.Count - 1)
info += (Ds.Cont_Payroll(i).Empl_id) & _
(Ds.ContPayroll(i).Reg_Hours)
Next i
messagebox.show(info.tostring)

it's not happening. i've declared DS as a dataset.then myDa as my dataadapter
and the sql string.
im sure there's something im missing.
any help or links / references to this subject would be greatly appreciated.
here's the code (sub proc) that handles the datagrid:

Private Sub export_vac()
Dim ds As New DataSet
Dim sql, empl, adoe, adate, adate2 As String
empl = UCase(txtEmpl.Text)
adate = daOne.Text
adate2 = daTwo.Text
'search export for vac doe's
Try
sql = "Select empl_id, NVL(reg_hours,0)as Reg,NVL(reg_rate,0)as Rate,NVL(doe,0)as Doe,NVL(neg_earn_ind,0)as Neg,ppe as Ppe,NVL(process_type,0) as Type,Balance_date as Bal_Dt,cheque_date as Ck_Dt,NVL(ot_code,0)as Ot,NVL(ot_hours,0)as Ot_Hrs,NVL(ot_rate,0)as Ot_Rt from cont_payroll where process_type ='P' and empl_id = '" & empl & "' and doe IN ('10','2A') and ppe between to_date('" & adate & "','mm/dd/yyyy') and to_date('" & adate2 & "','mm/dd/yyyy') order by ppe"

Dim oracon As New OracleConnection("Server=atserver;Uid='" & user & "';Pwd='" & pwd1 & "'")
oracon.Open()
ds.Clear()
ds.EnforceConstraints = False
Dim myCmd As New OracleCommand
myCmd.Connection = oracon
myCmd.CommandText = sql
myCmd.CommandType = CommandType.Text
Dim myDa As New OracleDataAdapter(myCmd)

myDa.Fill(ds, "Cont_Payroll")
If ds.Tables.Count = 0 Then
MessageBox.Show("nothing found")
ElseIf ds.Tables.Count >= 1 Then
DataGrid1.DataSource = ds.Tables(0)
Else
End If
oracon.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


as Usual thanks
rik


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
B

Bernie Yaeger

Hi Rik,

When you say 'it's not happening', is it throwing an error or is info simply
"". I don't know Oracle, but it must have a query analyzer - see if your
sql call returns any rows. On the other hand, if it's throwing an error,
what is the error?

HTH,

Bernie Yaeger

wrote in message news:[email protected]...
 
R

rbutch

no, the query is fine. it's when i try to reference specific tables/columns
normally when i used the server explorer,any kind of reference, like:
(ds.Cont_payroll(i).Empl_id) which is inside that for loop.

the error reads:

"Cont_Payroll is not a member of System.Data.Dataset"

whereas when i used the server explorer before the program was aware of what Table & Columns were involved before runtime.
sorry, is that any clearer?
thanks
rik

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
C

Cor Ligthert

Rik,

When you are not using the designer at all and are not making your strongly
typed dataset yourself, you are using just the dataset class (which is very
fine to use, because you have no extra problems in my opinion)

That dataset is an object, which only references to other objects.
ds.tables(0).rows(0).item(0)
ds.tables[0].rows[0].item[0]
When you use it, than this is the first itemopbject which is in the first
row which is in the first table in the dataset.

When you describe the dataset it is
ds.tables(0).columns(0) which describes the first item in the tables.
for C with brackets.

For use them you can tear this apart in everyway you want because it are
only references and nothing more.

Your solution start when you do this and nothing more create an SQL string
which you can afterwards put in a stored procedure, when you know it is
working.

Sqlstring = "Select * from mytable"
make your "new" connection, dataadapter and dataset. Than you can all your
needed data fill in one time in the dataset by using this command

da.fill(mydataset)

I have written it in this way to be program language and databaseprovider
independent. Because it is for all for the rest the same with some extra
words.

I hope this helps?

Cor
 

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