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

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
 
L

Lars Netzel

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top