- Executes a query, and returns the first column of the first row in the query-result set. - Additional columns and rows are ignored.
Questions tagged [executescalar]
153 questions
0
votes
3 answers
F# and ExecuteScalar casting
How can I use DbCommand.ExecuteScalar from F#? It returns an obj which I need to convert to an int. I'm very new to F# and the casting I need to do is not clear.
let (stockid:uint32) = command.ExecuteScalar()
Compile Error:
Type constraint…

MikeW
- 370
- 1
- 8
0
votes
3 answers
Select Command parameter issue
How do I properly declair a parameter in the code below. Im getting underlines on "SelectCommand" Im not sure what im doing wrong.
public int GetTotalNumberOfAprovedPictureIds(string SexType)
{
string strConectionString =…

CsharpBeginner
- 1,753
- 8
- 38
- 68
0
votes
3 answers
Order of executions or ExecuteScalar issue
First im inserting a new member into the members table. Then im querying the table to get back the Member id. I get the data into the table, but it does not apear there quick enough to do the query in the following lines.
I get this exception…

CsharpBeginner
- 1,753
- 8
- 38
- 68
0
votes
0 answers
An unhandled exception of type 'System.NullReferenceException' IN VB.NET
when comboxbox selects "NOINV" for which there is no value then an error appears how can I bypass the error.
Thanks
Private Sub DisTotal()
Dim query As String = "SELECT (DIS/BLC)*100 FROM RSG WHERE NOINV=@NOINV"
Try
…

roy
- 693
- 2
- 11
0
votes
2 answers
C# Using ExecuteScalar() Method With Where Clause in SqlCommand
try
{
SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) FROM Doctor WHERE Id = @id", sqlServerConnection);
sqlCommand.Parameters.AddWithValue("@id", id.Text);
int numberOfDoctors = (int) sqlCommand.ExecuteScalar();
…

Roller Fischer
- 19
- 3
0
votes
1 answer
SqliteCommand.ExecuteScalar() returns null (C# 5.0 and System.Data.Sqlite)
This code works!!!
DB path was wrong. Because of this, when I was executing:
dbConnection.Open();
Instead of opening my DB, I was creating an empty one.
Thank you all for your help!
The problem
I am using C#.NET 5.0 and System.Data.Sqlite to…

Iroqas
- 65
- 9
0
votes
1 answer
ExecuteScalarAsync() does not return the same value returned from stored procedure
I have a stored procedure that return either a positive integer or -1.
I have this code call that stored procedure and I don't know why it could not capture the value returned from the stored procedure
SqlConnection sqlConn =…

T L
- 504
- 2
- 11
- 27
0
votes
0 answers
ExecuteScalar not returning value when there should be one
I am calling ExecuteScalar with a valid value, and it worked on my previous one. I'm using using Oracle.ManagedDataAccess.Client;. Yet in this call it is returning null when the value should be 'Q'. Here is the code:
cmd.Parameters.Add(new…

Charlotte Williams
- 23
- 4
0
votes
1 answer
ExecuteScalar method to retrieve SQL Server 2019 table column list in Visual Studio 2019 c-sharp is incorrectly ASCII sorted
I have a table in my SQL Server database with the following stucture:
CREATE TABLE [file].[NumeTestINV](
[Category] [nvarchar](255) NULL,
[Class] [nvarchar](255) NULL,
[Company] [nvarchar](255) NULL,
[Division] [nvarchar](255) NULL,
…

shawnmandel
- 39
- 9
0
votes
1 answer
Get value from sql select if parameter may be null
Looking for a method to get value of first row in first column from arbitary sql query in ASP.NET MVC Core application using EF Core.
Like
var total = ctx.ExecuteScalar(@"select ... where p1={0}", null);
Tried…

Andrus
- 26,339
- 60
- 204
- 378
0
votes
1 answer
vb.net - Object reference not set to an instance of object
I got this error when trying to use parameters to my sql statement, but it works fine when not use it. My codes are below:
Dim i As String
Dim sql as String
sql = "SELECT * FROM tblStaff WHERE Username = @User AND Password = @Pass"
myCommand =…

Tepken Vannkorn
- 9,648
- 14
- 61
- 86
0
votes
0 answers
Dynamic SQL Query in C#
I'm trying to create a query with a variable number of parameters, giving to the program the name of the table and an Array for the names of parameters and another array for their values.
It seems to do the work but at the instruction…

BlackHole
- 1
- 1
- 5
0
votes
1 answer
Data type mismatch using execute scalar
I'm looking to fetch sum of ALLOCATED_DEPOSIT from Allocations using Invoice_No. I'm getting all the details through datareader but only execute scalar is being a problem for me. I tried everything but using the following code it gives "data type…
0
votes
1 answer
Select with a ExecuteScalar() not working when i use a variable, always return empty, when i don't use variable it works - C#
When I use a variable, the result of command.ExecuteScalar() it's always empty (blank), I'm not receiving any error messages, just a blank value,
but when I use the same SQL query without using a variable it works.
What I have tried so…

José Souza
- 41
- 2
0
votes
0 answers
Checking if record exist for 2 datatable
I am trying to check 2 different datatable to see if the workorder exist. . Both the datatables have the same columns with different table name [c# barcode] and [c1 barcode]. The first check if there is the same workorder at [c# barcode]is working…

darren
- 39
- 5