working with datasets

Status
Not open for further replies.

russ-iha

Ars Praefectus
4,407
Subscriptor
What's wrong with this code?

code:<HR>
Code:
            Dim dbSet As New Data.DataSet()
            dbAdapter.Fill(dbSet, "WAITING")<P>            For t = 0 To dbSet.Tables("WAITING").Rows.Count - 1
                SendMsgToClient(myClient, dbSet.Tables("WAITING").Rows(t).Item("ID"), _
                        dbSet.Tables("WAITING").Rows(t).Item("data"))
                dbSet.Tables("WAITING").Rows(t).Delete()
            Next<P>            dbAdapter.Update(dbSet, "WAITING")
            dbAdapter.Dispose()


The idea is that it gets all the items from the table, sends them, then deletes them and updates the table with new deletes.

It gives an error about no corresponding delete statement when a dataset contains deletes (???)

[This message was edited by russ-iha on February 17, 2002 at 03:28.]
 

wb

Ars Legatus Legionis
25,208
Subscriptor
I'm sorry, I may be a moron, but where's that code coming from (i.e. what langugae are you speaking?)

Looks like VBScript to me.

If so, I'd like to point out some syntactical errors in the way you are using the language, which might be the source of your problems. In VB you should only use parentheses "(" and ")" around a function argument list when you are explicitly using the return value of a function. When calling a subroutine, or when calling a function where you don't check the return value, DO NOT USE PARENTHESES! I guess the excpetion is when you are using the "call" function, which you are not.


Syntactically VB is not doing what you think it is. E.g.:

code:<HR>
Code:
dbAdapter.Update(dbSet, "WAITING")
Should read:
code:<HR>
Code:
dbAdapter.Update dbSet, "WAITING"

However, when you use the return value, you need parentheses to identify the function. e.g.:
code:<HR>
Code:
If checkForUserInput() Then
   result = scanForMouseEvents( mouseHandler, eventQueue )
End If

If I weren't using the return value from scanForMouseEvents, though, I'd have to say:

scanForMouseEvents mouseHandler, eventQueue

Because otherwise VB will interpret parenthetical expression "(mouseHandler,eventQueue)" as a single expression, not as two function arguments.

Likewise you should leave off the parens when you are creating your variable (although this doesn't have any bad side effects that I know of, it's still not really correct):

Dim dbSet As New Data.DataSet
 

russ-iha

Ars Praefectus
4,407
Subscriptor
Yes, its VB.NET.


I just got a lecture in VBScript. ROFL.

Anyway, here's the full code:

code:<HR>
Code:
        Try
            Dim strSQL As String = "GetWaitingByUser '" & myClient.myName & "'"
            Dim dbAdapter As New SqlClient.SqlDataAdapter(strSQL, myClient.dbConn)<P>            'now fill dataset
            Dim dbSet As New Data.DataSet()
            dbAdapter.Fill(dbSet, "WAITING")<P>            If dbSet.Tables("WAITING").Rows.Count > 0 Then
                myClient.send("GETWR" & vbCrLf & "Status: sending")
                For t = 0 To dbSet.Tables("WAITING").Rows.Count - 1
                    myClient.send(dbSet.Tables("WAITING").Rows(t).Item("data"))
                    dbSet.Tables("WAITING").Rows(t).Delete()
                Next<P>                dbAdapter.Update(dbSet, "WAITING")
                dbAdapter.Dispose()
            Else
                myClient.send("GETWR" & vbCrLf & "Status: none")
            End If<P>        Catch e As Exception
            myClient.send("Error: " & e.Message)
            Exit Sub
        End Try

Still getting the error :confused:
 
Status
Not open for further replies.