why code for datagrid doesn't work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have confirmed that the following SQL string works in Access:
SELECT[MRN],[MemNAME],[DOB],[SEX],[SSN],[GROUP],[SGR],[FROM-DT],[THRU-DT]FROM MEMBERSHIP WHERE [MemName] like 'duld*';

I have also confirmed that it is successfully passed as a Public String
into strMemberSQL

So why won't it successfully open my datagrid in this code?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

dcMalpha.Open()
'Set the new adapter with the appropriate SQL string from above
Dim daMembers As New OleDb.OleDbDataAdapter

daMembers.SelectCommand = New OleDb.OleDbCommand(strMemberSQL,
dcMalpha)
Me.lblSQL.Text = strMemberSQL

Dim dsMembers As New DataSet
daMembers.Fill(dsMembers, "Membership")

dcMalpha.Close()

DGMembers.DataSource = dsMembers.Tables("Membership")
DGMembers.DataBind()

End Sub
 
Jonefer,

Assuming that it is a webdatagrid than this should be enough (I thought that
you have used the command mixed up with the constructor of the adapter)

\\\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim daMembers As New New OleDb.OleDbDataAdapter(strMemberSQL,
dcMalpha)
Dim dsMembers As New DataSet
daMembers.Fill(dsMembers, "Membership")
DGMembers.DataSource = dsMembers.Tables("Membership")
DGMembers.DataBind()
End Sub
///

It is better to do it like this.

\\\
Try
daMembers.Fill(dsMembers,"Membership")
Catch ex as exception
'write ex.tostring error to logsystem and redirect a message to the page
End try
///

I hope this helps,

Cor
 
Back
Top