Questions tagged [executescalar]

- Executes a query, and returns the first column of the first row in the query-result set. - Additional columns and rows are ignored.

153 questions
0
votes
1 answer

Using statement with a scalar query

Can you show a coding example that has the "Using" statement with a scalar query? I could not find any sample coding for this by searching yet.
Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152
-1
votes
2 answers

ExecuteScalar compilation error

I'm getting an error on ExecuteScalar(). It says I must declare the scalar variable @PicID. How could I declare a scalar varaible? Or am I doing this entire function incorrectly? public int GetTotalNoVotes(int PicRating, int PicID) { …
CsharpBeginner
  • 1,753
  • 8
  • 38
  • 68
-1
votes
1 answer

why do i get error Must declare the scalar variable "@x". while the query works in the sql window?

the error that I'm getting is " Must declare the scalar variable "@x"." I'm trying to declare a variable @x and make him a NVARCHAR(50) then id like to subtract an amount from it called @z and finally update a Table in the server called Stock with…
-1
votes
1 answer

Problem with taking data from a table using Execute Scalar (C#)

I have two tables, one called DogContract and one called WeeklyBooking. They both share two columns, called ContractLength and DogID. I am currently programming a function for the user to use the GUI to input a new WeeklyBooking object into the…
-1
votes
2 answers

C# ExecuteScalar()

I am attempting to make a craps game, store users/game data etc. In this problem I am attempting to see if a username is already taken. But for some reason, regardless of how I try to declare my variable to take in the result of ExecuteScalar(), I…
-1
votes
1 answer

SQL execute scalar returning NULL

queryShelf = "SELECT * FROM shelftable WHERE ShelfId= @ShelfId"; //Create Mysql Command MySqlCommand cmd = new MySqlCommand(queryShelf, connection); cmd.Parameters.Add(new MySqlParameter("@ShelfId", MySqlDbType.VarChar)).Value =…
Ferooz Khan
  • 93
  • 3
  • 11
-1
votes
2 answers

How to Safely Query for a Potentially Nonexistent Value in SQLite?

I've got this code, which works as long as there is a matching value in the database: public String GetDeptNameForDeptId(int deptId) { String deptName; const string qry = "SELECT Name FROM Department WHERE Id = @deptID"; try { …
-1
votes
2 answers

How can I pull out the Max value of a field with the name on that record?

How can pull selected fields of a record from an access database and put it into a label? This is what I have so far: Using conn As New OleDbConnection(Get_Constring) conn.Open() Using cmd As OleDbCommand = conn.CreateCommand If cb_Stat.Text =…
dave
  • 41
  • 1
  • 6
-1
votes
2 answers

Close connection after calling ExcuteScalar

i have the following function, the problem is since im using ExecuteScalar, the connection never closes when using any other function again... Public Function Valor(tabla As String, campos As String, condicion As String) cn.Open() …
JavierM
  • 11
  • 2
-1
votes
1 answer

ExecuteScalar() error

I want to create a Log In form with C#. If the username and password is correct, I do not get an error, but if it's wrong then I get an error in this line: int count = Convert.ToInt32(cmd.ExecuteScalar().ToString()); log in form code: if…
user2979362
  • 13
  • 1
  • 3
-1
votes
1 answer

How to execute a stored procedure containing INSERT and SELECT both statements

In my stored procedure, first i do INSERT query and then have SELECT statement as follow: INSERT () SELECT * FROM preferences WHERE ID=@ID In ADO.NET, i have used - datareader to execute this procedure. But, it does not return the…
user3711357
  • 1,425
  • 7
  • 32
  • 54
-1
votes
2 answers

ExecuteScalar always returns 0

I'm not sure why this is happening. I've seen the same issue online with little help out there to correct it. When i run my query inside Access i get different values ranging from 0 - 10 but for some reason, it won't return that same value inside my…
MaylorTaylor
  • 4,671
  • 16
  • 47
  • 76
-1
votes
3 answers

Creating a class for this operation

i'm picking up datas from a mysqldatabase and throwing in variables in a C# application. I'm using this code : int forcatime; string comandomedia = "select avg(forca_jogador) from jogadores where nome_time = " + time; ocon.ConnectionString =…
-2
votes
2 answers

Adding to a sql integer column using C#

I am trying to update a SQL table from my C# backend, but it never successfully executes; mainServiceButton is a pre-existing value in the linkName column. Here is what I have so far: conn.Open(); string qry = "UPDATE clickStream SET…
Douglas Tober
  • 300
  • 4
  • 15
-3
votes
1 answer

System.InvalidOperationException: 'Connection must be valid and open.'

I am developing a program in C # with .NET and MySQL databases. I need the user image to be visible once the user is logged in, for which I have a LONGBLOB type column called 'Image'. The login process was good, but the following error…
1 2 3
10
11