[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Problem with OleDb.OleDbCommand.ExecuteScalar

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
ur_cherub
Asked:
ur_cherub
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
ur_cherubAuthor Commented:
Thank u very much emoreau...
very stupid of me to have left that out...

thanks a lot
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now