Syntax Question - Novice Question

  • Thread starter Thread starter sean
  • Start date Start date
S

sean

Hi,

I am filling a datagrid and I was wondering how I can test for "end of file"
and then make decisions based on that. I am still making the transition from
asp to asp.net.

Could someone help me with the syntax please?

Thanks in advance for youe answer

Sean



Dim Conn As OleDbConnection

Dim Rdr As OleDbDataReader

Try

Dim strConn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="

strConn &= Server.MapPath("clicks.mdb") & ";"

Dim strSQL As String

strSQL = "select FirstName from newsletter where FirstName='sean'"

Conn = New OleDbConnection(strConn)

Dim Cmd As New OleDbCommand(strSQL, Conn)

Conn.Open()

Rdr = Cmd.ExecuteReader()

MyDataGrid.DataSource = Rdr

MyDataGrid.DataBind()

Catch exc1 As Exception

Label1.Text = exc1.ToString()

Finally

If Not (Rdr Is Nothing) Then

If Rdr.IsClosed = False Then Rdr.Close()

End If

If Not (Conn Is Nothing) Then

If Conn.State = System.Data.ConnectionState.Open Then Conn.Close()

End If

End Try
 
The norm, in .NET, is to bind rather than curse through data.

// actual name of object goes after =
DataGrid1.DataSource = {DataSet, DataTable, DataView, DataReader};
DataGrid1.DataBind();

As such, you do not have to find EOF unless you are writing out the table
yourself. If you are aiming this direction, you will likely be using a
DataReader. The norm is to use a Do loop and loop as long as Read() returns
true.

Hope this helps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top