Simple SQL question. Can you check what am i doing wrong? Thank You.

  • Thread starter Thread starter Miguel Dias Moura
  • Start date Start date
M

Miguel Dias Moura

Hello,

i have an ASP.net / VB page which i want to display 1 record of a database
acording to this:

1. The page receives a variable name "Explicador" in the URL. Example:
"Explicador = Jonh Smith"
2. The database where the records are is named "explicador"
3. Two of the database fields are "NomePrimeiro" and "NomeUltimo". The
"Explicador" field is created as follows:
"Explicador" = "NomePrimeiro" + " " + "NomeUltimo"

The SQL code i am using is this:

SELECT *, NomePrimeiro + ' ' + NomeUltimo as Explicador
FROM explicador
WHERE Explicador = ?

<Parameter Name="@Explicador" Value='<%#
IIf((Request.QueryString("Explicador") <> Nothing),
Request.QueryString("Explicador"), "") %>' Type="WChar"
/></Parameters></MM:DataSet>

Can you tell me what am i doing wrong?

Basicly when the URL has Explicador = John Smith, it should be loaded the
record that has NomePrimeiro = "John" and NomeUltimo = "Smith"

I am getting this error:

System.Data.OleDb.OleDbException: No value given for one or more required
parameters.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandB
ehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable)
at DreamweaverCtrls.DataSet.DoInit()

Thank You,
Miguel
 
Since you are using the = ? way of using parameters, you need to set the
parameter befor eyou start retrieving data from the Seledt statement.

In the Adapter add the parameter before you fill.

Me.OleDbDataAdapter1.SelectCommand.Parameters("name") = New
OleDb.OleDbParameter("name", "value")

Maybe this will help you?

/Lars
 
Back
Top