Solved

Problem with OleDb.OleDbCommand.ExecuteScalar

Posted on 2004-03-31
2
496 Views
Last Modified: 2013-12-25
Hi Experts,

I'm having a problem with the following piece of code.. Don't kno the reason for it and how to go bout correcting it...

---------------------------------

Dim Cmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT UserName FROM Login WHERE UserName=" & txtUser.Text, Conn)

Dim userid As String = New String(CStr(Cmd1.ExecuteScalar))

---------------------------------

('txtUser' is a text box and 'conn' is an OleDbConnection). The error i'm getting is
      "No value given for one or more required parameters." for the second Dim statement...

pls help me out...
thank u...
0
Comment
Question by:ur_cherub
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 20 total points
ID: 10722639
since it is a character field, you need to put quotes around the value:

Dim Cmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT UserName FROM Login WHERE UserName='" & txtUser.Text & "'", Conn)

0
 

Author Comment

by:ur_cherub
ID: 10722758
Thank u very much emoreau...
very stupid of me to have left that out...

thanks a lot
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question