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

The Connection is not open while in function using C#

Method that I use for handling ExecuteScalar Postgresql queries: public T ExecuteScalar(string sql, CommandType commandType, List parameters) { using (NpgsqlConnection conn = Konekcija_na_server.Spajanje("spoji")) …
Marko Petričević
  • 333
  • 2
  • 9
  • 20
0
votes
1 answer

ADO.Net - Performance difference between Execute Reader and Execute Scalar

I know the purpose of Execute Reader and Execute Scalar. But Execute Reader can serve the purpose of Execute Scalar. So why to use Execute Scalar? Is there any performance difference between them? Which is faster? Thanks.
0
votes
1 answer

unable to update the oracle DB using ExecuteNonQuery()

Please find the source code below. I am not getting any error but _oracleCommand.ExecuteNonQuery() is going infinite - debugger is not moving to next line. I am able to update the data using Toad. I am stuck with this. public void…
Hardy
  • 629
  • 3
  • 8
  • 20
0
votes
2 answers

How can I use ExecuteScalar in this scenario?

I have this SQL Select statement to select the basket id where the user id equals a specific ID. I want to store the result of the query in a variable, so I thought I could have done: BasketPage.SelectCommand="SELECT BasketID FROM tblBasket WHERE…
user520351
0
votes
0 answers

ORACLE DB: insert a row and return a variable to a scalar query

Environment: Oracle DB (12c) C# application to call the db The expected outcome is to add new row into a table and return an id column which is auto-incremented using a sequence. The caller is a c# application which uses executeScalar to execute…
Mario
  • 767
  • 1
  • 14
  • 42
0
votes
0 answers

Operation is not valid due to the current state of the object on ExecuteScalar DateTime

Getting operation in not valid error when doing ExecuteScalar() to return a date. No errors on compile and I'm not sure why this isn't working - message is not helping me understand. Any thoughts? using (OracleConnection con = new…
Dolphie97
  • 1
  • 1
0
votes
1 answer

ExecuteScalar not throwing exception

I am trying to inser data in main and detail tables. My Main Table Qry: Insert INTO tblMain(); Then I am doing: declare @OrderID as int; set @OrderID=scope_identity(); Update Orders SET OrderID=(LTRIM(RTRIM(OrderID))+ RIGHT('0000000'+CAST(@OrderID…
ManojK
  • 21
  • 3
0
votes
2 answers

Preventing SQL from injection attacks

I have a program that contains SQL queries, and it was pointed out to me yesterday that it was wide open to SQL injection attacks. After doing some research, I could see that to fix this, I needed to use parameters instead. I have the following…
user6579928
0
votes
1 answer

MS SQL function not returning value to C#

I've got the following MS SQL function: CREATE FUNCTION [dbo].[fn_NumApplications] () RETURNS int AS BEGIN DECLARE @numRecords int = 0 SELECT @numRecords = COUNT(A.id) FROM Applications A RETURN @numRecords END and the following C# code to call the…
0
votes
1 answer

Invalid attempt to call Read when reader is closed error when call ExecuteScalar method

I have an ASP.NET application that need to load data fro excel file. The file contains about 20K records. The app reads the data from the file and loop through each record, makes calculations and validations and then insert each record into a DB.…
Lev Z
  • 742
  • 9
  • 17
0
votes
1 answer

Select Count query in DB2 with Array

I am trying to Count all records in my DB2 database with a query where is uses the contents of an Array to search the Table. string[] strNumbers = txtNumbers.Text.Split(new string[] { Environment.NewLine },…
0
votes
1 answer

ExecuteScalar: Connection property has not been initialized. SQL Server Connection

I wrote this code to read the images stored in SQL Server database however I got this error: ExecuteScalar: Connection property has not been initialized. Since I already initialized the connection, I am not sure what the problem is. SqlConnection…
Abahr
  • 3
  • 3
0
votes
1 answer

How can I use executereader for different variables?

I use ExecuteScalar for single query like this: try { OleDbConnection Connection; using (Connection = new OleDbConnection("Provider=MSDAORA.1;Data Source=DATABASE:1521/orcl;Persist Security Info=True;Password=PASSWORD;User ID=USERNAME")) …
onur
  • 5,647
  • 3
  • 23
  • 46
0
votes
1 answer

Inserting data after checking if table is empty

I have a server program that will store certain data sent by the client. One data is the client's hostname. The server will check if the hostname exist, if not then it will insert that new data. It should look like this. hostname_id |…
charlie9495
  • 87
  • 2
  • 17
0
votes
1 answer

ExecuteScalar returning wrong value

I have a little problem with selecting max ID from my database. This is my code: string checkcat = "SELECT MAX(PRODUCT_ID) FROM CMS_PRODUKTY WHERE (CATEGORY_ID = CATEGORY_ID) AND (CLIENT_ID = @CLIENT_ID)"; SqlCommand cmd2 = new SqlCommand(checkcat,…
Ashiv3r
  • 894
  • 4
  • 14
  • 28