- 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
1 answer
System.InvalidCastException: Specified cast is not valid at .ExecuteScalar
I'm working on an app linked to a local database. What I want, is to show in a form datae from database, but in labels. I created a list of labels, but I get this error at command.Executescalar(), where I try to get the number of rows entered in the…

Ezekiel
- 333
- 4
- 9
- 27
0
votes
1 answer
ExecuteScalar not passing the right parameter. always returns 0
I' so lost.... This is my stored proc:
@User_ID INT,
@Form_NAME NVARCHAR(25)
AS
BEGIN
DECLARE @Count int = 0
DECLARE @myReturnCode INT
SELECT @Count = COUNT (tblForms.Form_Name)
FROM tblForms INNER JOIN
…

gadi
- 481
- 3
- 14
- 32
0
votes
2 answers
mysql command executescalar returns null in C#
Let's say I have a query result that looks as follows:
ID NAME Phone
---- ---- -----
1 John 123456
2 John 125678
3 John 345678
4 Abby 456789
5 Abby 567890
I want to return just a single row instance of…

rfa
- 53
- 1
- 7
0
votes
3 answers
Execute Scalar to Label. Subquery returned more than 1 value
So I have a label which shows the username of the user. I've used this value to return their ID which I then attach to a label. I used execute scalar to do this because I wasn't sure how else to get a single value on a label.
This works fine. I then…

evanna
- 1
- 5
0
votes
1 answer
When i use ExecuteScalar command returns an empty object
What is wrong with my code?
When I use this block of code in Visual Studio 2008 C# the curid output value is "", where I have 2 values in my database so it should return 2...
Also when I run a query
select IDENT_CURRENT('tablename')
directly in…

anotherday
- 23
- 3
0
votes
1 answer
How to handle DBNull? VB.NET
I have form that has datagrid and some textbox controls.
Basically, Im performing Add function. Whenever I add, it scans the maximum value and it will increment by one. I only designed for auto increment. My problem is, how can I increment when the…

Fvcundo
- 95
- 2
- 3
- 11
0
votes
1 answer
ExecuteScalar with formview
i have form view i wrote this code in event sqlds_inserted
text1.text=e.Command.ExecuteScalar().ToString();
to have the id for the last inserted record
it works but every time i add record it inserts tow records with the same data
when i delete…

TARIK
- 1
0
votes
1 answer
How can I get the actual datetime values from a SQLite table?
I am querying a SQLite table which has a DateTime member:
public class PhotraxBaseData
{
[SQLite.PrimaryKey]
[SQLite.AutoIncrement]
public int Id { get; set; }
. . .
public DateTime dateTimeTaken { get; set; }
. . .
The…

B. Clay Shannon-B. Crow Raven
- 8,547
- 144
- 472
- 862
0
votes
2 answers
ExecuteScalar - Specific Column
my plans table has 15 fields, using ExecuteScalar seems to grab the result from the first column only, how do I specify the column name that I want? for example when I run the code below, it will return 1 which is the value in my ID column, but I…

user3345212
- 131
- 1
- 5
- 15
0
votes
0 answers
How to fill datagridview column with sql scalar function in C#?
hi all i am having a problem with returning a value of a sql server scalar valued function in a specific datagridview column, the code is below:-
1- sql function:-
CREATE FUNCTION [dbo].[ToLocationID](@ID int)
RETURNS varchar(50)
AS
BEGIN
--…

user3804193
- 113
- 4
- 11
0
votes
1 answer
Error on SQL count into ExecuteScalar()
When executing the below code I get the following error.
"Additional information: Conversion from string "_01202478334" to type 'Double' is not valid."
Code:
Using connn As New SqlClient.SqlConnection("server=inlt01\SQLEXPRESS;…

user3580480
- 442
- 7
- 14
- 45
0
votes
0 answers
OleDbConnection takes long time or give error on unc path
I am using C#.NET Application.
Having One Query which Executed With OldDbProvider.
System.Data.OleDb.OleDbConnection oleCon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + ";");
try
…

user2071694
- 1
- 1
0
votes
1 answer
when using ExecuteScalar it writes 2 Records instead of one
I need to know what order number has been written to the database. To achieve this I use the SQL expression EXECUTESCALAR.
I debugged the program and monitored the database. The record is written once into the Database when I execute the 2nd…

Rene
- 29
- 1
- 9
0
votes
1 answer
error when i insert data and select last id
I want to get id after I insert a row of data into a table but I get an error:
System.InvalidCastException: Specified cast is not valid.
This is my code
SqlCommand cmd_insert = new SqlCommand("insert into ITM_OrderItem (ITM_Code, ITM_Desc,…

user3001046
- 235
- 1
- 10
- 28
0
votes
1 answer
oracle ExecuteScalar in parallel programming sometimes returns null
I used parallel programming to perform two parallel oracle database queries.
Sometimes the "res" object returns as null.
Any idea why? Note that this is a count query of the same table and nothing is modifying this table so the database table and…

max
- 9,708
- 15
- 89
- 144