Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with OleDb.OleDbCommand.ExecuteScalar

Posted on 2004-03-31
2
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 80 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 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