Fill question

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

Does a Fill command make an automatic connection when initiated? When it is
through does it automatically disconnect?

I am just wondering if I need something like the following around a fill
command?

mySqlConnection = New SqlConnection(myConnectionString)

DaContracts.Fill(DsMain1, "Contracts")

mySqlConnection.Close()
 
No, fill won't open or close the connection for you. You must have it open
first and close it after.
 
Hi Woody,

Yes, it does Open an connection related to adapter's SelectCommand (however
it does *not* create a connection instance).
The logic is: if the connection is closed, open it and after Fill has ended,
close it.
If you need only one Fill in a row it is ok.
However, if you have more than Fill in row you might consider using explicit
Open/Close block - don't forget to put it in try/finally block.
 
Hi Woody,

Yes the fill opens a connection, and therefore I could in the VB language
group make my try, catch finaly and end try example in an other way as the
others.

But it does not close it, so have a look at that sample in the VB.language
group.
Everything including close is in it.

This is not for an reader, what was your other example.

:-)

Cor
 
If I understand you correctly something like the following is required. Y/N?

Try

If mySqlConnection.state <> ConnectionState.Open then
mySqlConnection.Open
End If
DaContracts.Fill(DsMain1, "Contracts")
DaArd.Fill(DsMain1, "ard")
DaFunding.Fill(DsMain1, "Funding")
DaFinSmry.Fill(DsMain1, "FinSmry")
DaDownPay.Fill(DsMain1, "DownPay")
DaStretch.Fill(DsMain1, "StretchPay")
DaComments.Fill(DsMain1, "Comments")
Catch ex As Exception
MsgBox(ex.tostring)
Finally
If mySqlConnection.State = ConnectionState.Open Then
mySqlConnection.Close()
End If
End Try
 
Woody Splawn said:
Does a Fill command make an automatic connection when initiated? When it is
through does it automatically disconnect?

From the docs for DataAdapter.Fill(DataSet):

<quote>
The connection object associated with the SELECT statement must be
valid, but it does not need to be open. If the connection is closed
before Fill is called, it is opened to retrieve data, then closed. If
the connection is open before Fill is called, it remains open.
</quote>
 
Hi Jon,

You are right,
The connection object associated with the SELECT statement must be
valid, but it does not need to be open. If the connection is closed
before Fill is called, it is opened to retrieve data, then closed. If
the connection is open before Fill is called, it remains open.

I had always the idea that the connection did stay open so had to be closed
(my favor) but it is not even needed to close it.

Or you should do an multiple fill operation as Miha sugested

Thanks,

Cor
 
Back
Top