Error filling datagrid

A

Adam Maltby

Hi I am trying to fill a datagrid using the following snippet:
GetSQL = "Select QID, Q, A, B, C, D, CorrectAnswer, Expired " & _
"From Questions " & _
"INNER JOIN " & _
"QuestionTypesList ON Questions.QTID = QuestionTypesList..QTID " & _
"WHERE (QuestionTypesList.QuestionTypes = '" & QsetSelected & "')"

rs.Close()
rs.Open(GetSQL, ConfigCN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
rs.MoveFirst()
Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim ds As DataSet = New DataSet
Try
da.Fill(ds, rs, "QTable")
Catch ex As Exception
MsgBox(ex)
End Try
DataGrid1.DataSource = ds.Tables(0)

But when I do I get a catch error when trying da.fill:
Argument 'Prompt' cannot be converted to type 'String'.

Any ideas/suggestions welcome!

Cheers
Adam
 
G

Guest

Adam,

Is the QsetSelected a object, like a select list or something. If so, what
is its default property? And what is it putting into your GetSql string.
Debug.write your GetSql string out and make sure that the WHERE clause looks
correct.

Aaron
 
E

Earl

Use a simpler method of filling the datatable, without the recordset, maybe
something like this:

Dim GetSQL As String = "Select QID, Q, A, B, C, D, CorrectAnswer, Expired "
& _
"From Questions " & _
"INNER JOIN " & _
"QuestionTypesList ON Questions.QTID =
QuestionTypesList.QTID " & _
"WHERE (QuestionTypesList.QuestionTypes = '" & QsetSelected
& "')"
Dim strOle As New OleDb.OleDbConnection (ConfigCN)
Dim da As New OleDbDataAdapter(GetSQL, strOle)
Dim ds as New Dataset
strOle.Open()
da.Fill(ds, "Qtable")
strOle.Close()
 
A

Adam Maltby

Hi Earl,

Thanks for that, once I pasted in your code i did a SetDataBindings on the datagrid and it all fell into place!


Adam
 

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