- 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
0 answers
How to fix executescalar not having an output
I'm using asp.net MVC to make an app which calculates if multiple political parties can work together to form a legitimate coalition. (Have a majority). When i make a coalition i need to return the id of the coalition, which is an auto increment.…

Jesse Oosterwijk
- 27
- 1
- 6
0
votes
1 answer
How to get single row/record from a SQL query using command.ExecuteScalar in VB.NET
I'm trying to get a single row by executing a SELECT statement with a primary key
I have tried to assign the output of command.ExecuteScalar() to an Object variable then tried accessing the values by key like obj('column_name')
Using conn As New…

Redgren Grumbholdt
- 1,115
- 1
- 19
- 36
0
votes
3 answers
How do I use ExecuteScalar with a stored Procedure?
I'm trying to get a count of column records in a Sql database and show the result in a MessageBox.
This is my code:
public DataTable CheckIfNameExist(string name)
{
con = Connect();
cmd = new SqlCommand();
cmd.Connection = con;
…

Neod
- 21
- 1
- 5
0
votes
1 answer
commandtext parameter changes type when executing
I have a problem in my c# application, when executing a commandtext on an ms-sql-server. Here is the function i use:
public T ExecuteScalar(string commandText, IDbDataParameter[] parameters)
{
T result_value = default(T);
using (var…

Olli
- 658
- 5
- 26
0
votes
2 answers
how to find out ExecuteScalar() is dbnull
How do I check to see if the result of ExecuteScalar() has no data? Checking if it is nothing does not work.
My code:
Dim cmdCode As New OracleCommand
cmdCode.Connection = sgcnn
cmdCode.CommandText = "select max(SUBSTR(client_code,4,7)) from…

Ejaz Sarwar
- 37
- 1
- 1
- 8
0
votes
1 answer
Execute a stored procedure multiple times in the same connection
Is this even possible with the command object? I need to change this piece or code to run a proc (sp_insertRecord) multiple times for the set of Parameters (created from the Records List object) in the same connection based. Right now it creates…

Southern Coder Chic
- 71
- 2
- 8
0
votes
1 answer
Need Help - Method Stays in Limbo
Sorry, the title may not look/sound meaningful, that seems to be the best I can come up with.
I have an application with the code below as part of it which was working fine until today and I seems not to be able to figure out what the problem is.…

Ibroshine
- 13
- 4
0
votes
1 answer
Using ExecuteScalar() results in a call to ExecuteReader() with a "default" CommandBehaviour?
Stack trace shows that ExecuteReader is the underlying method for ExecuteScalar.While digging for associated commandbehaviour, i found the post below - stating that the commandbehaviour.default is used by the reader.
Does ExecuteScalar() have any…

MZZ
- 3
- 1
0
votes
1 answer
executescalar: Object cannot be cast from DBNull to other types
I'm having a problem when there is no data/value is fetch during running the program, I get the following error:
Object cannot be cast from DBNull to other types.
I tried validating it using if dr.hasrow() but I still get errors.
drqry = "SELECT…
0
votes
1 answer
SqlCommand string to RowdataBound Header
I have created a method with a string "test" that holds my SqlCommand query.
test = '201813'
public void temp()
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new…

Nils
- 516
- 3
- 9
- 33
0
votes
2 answers
Display SQL query result from dropdown list selection in a label in asp.net form
I'm trying to display the SQL query result in a label but it's not showing. The user picks a value from the dropdown list and the label should populate the result. a This is my code:
protected void drpEmployeeName_SelectedIndexChanged(object sender,…
0
votes
3 answers
OverFlowException on Executescalar on vb.net
I'm working in asp.net with vb.net and in the backend I'm trying to select something from the database.
But whenever I ask to execute the query it gives an error which says 'OverflowException Ocuured'. The query that is made works perfectly in my…
0
votes
2 answers
ExecuteScalar throws NullReferenceException when calling a stored proc that returns 1
I've done some research before posting this question and I'm aware of the fact that when there's no data returned, ExecuteScalar will throw a System.NullReferenceException. That is why I modified my stored proc to "return 1" so there's guaranteed a…

Bryan
- 3,220
- 3
- 26
- 31
0
votes
2 answers
Unable to insert record using the ExecuteScalar or ExecuteNon-Query
I have a database with a role sa.
When I execute the stored procedure which inserts a record to the table. However, when I run the same stored procedure via the ADO.NET code, the record is not getting inserted successfully. However, I can see that…

Dev
- 1,451
- 20
- 30
0
votes
1 answer
ExecuteScalar not returning right values C#
Let me start by posting my code first:
ExecuteScalar method:
public T ExecuteScalar(string sql, CommandType commandType, List parameters)
{
using (NpgsqlConnection conn = Konekcija_na_server.Spajanje("spoji"))
{
…

Marko Petričević
- 333
- 2
- 9
- 20