0

I'm using this code below to return some data from an access database using a query with a parameter passed to it:

    Dim con As OleDbConnection = New OleDbConnection(GlobalVariables.connectionString)
    Dim cmd As New OleDbCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "Q_VIEW_SINGLE_TEST"
    cmd.Parameters.Add("@TEST_ID", OleDbType.VarChar).Value = "17"  ' Add Parameter
    cmd.Connection = con
    con.Open()
    Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    Dim ds As DataSet = New DataSet()
    da.Fill(ds, "Table1")
    dt = ds.Tables("Table1")

    MsgBox(ds.Tables(0).Rows(0)(3))

It just keeps returning the old data however (so the data which was being returned when value was equal to 1:

   cmd.Parameters.Add("@TEST_ID", OleDbType.VarChar).Value = "1"

What am I missing here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ar.dll
  • 767
  • 4
  • 16
  • 35
  • Are you sure that the field used for the comparison with the parameter @TEST_ID is a string field? And could you post the code of the query "Q_VIEW_SINGLE_TEST"? – Steve Aug 12 '13 at 16:48
  • 1
    Make sure you are pointing towards the correct database. – NeverHopeless Aug 12 '13 at 17:11
  • Just try `cmd.Parameters.AddWithValue("@TEST_ID", "17")` – APrough Aug 12 '13 at 17:58
  • is the Access DB file open? – Michael B. Aug 13 '13 at 01:06
  • yes access was open, tried with it being closed same result, tried "cmd.Parameters.AddWithValue("@TEST_ID", "17")" same result :( – ar.dll Aug 13 '13 at 08:24
  • code for query: SELECT TESTS.TEST_ID, TESTS.MODULE_NO, TESTS.TEST_NAME, TESTS.TEST_DESCRIPTION, TESTS.AUTHOR, TESTS.PATH, TESTS.CUSTOM_BATCH, METRICS_EXPECTED.STANDARD_CHK, METRICS_EXPECTED.BITMAP_CHK, METRICS_EXPECTED.TEXT_CHK, METRICS_EXPECTED.TEXT_AREA_CHK, METRICS_EXPECTED.REPORTER_CHK FROM TESTS INNER JOIN METRICS_EXPECTED ON TESTS.TEST_ID = METRICS_EXPECTED.TEST_ID; – ar.dll Aug 13 '13 at 08:25

0 Answers0