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
1
vote
1 answer

how to get the value of a last inserted calculated column in sql server and show to a user after submitting form in asp.net

I have tried yet no answer. I have a table with a calculated column known as ApplicationNo that has prefix 'CHV18' with 000000 and then the identity column values is attached to it form something like CHV180000001, CHV180000002 etc. Now i want to…
Paschal
  • 27
  • 1
  • 10
1
vote
1 answer

ExecuteScalar with WHERE clause not matching all rows

I have been researching why my below OleDBCommand ExecuteScalar function is not properly returning the correct data. query = "SELECT Count(*) FROM NoteTable WHERE SQLMigrationFl <> 'Y'"; command = new OldDbCommand(query, connection); var…
Jason W
  • 682
  • 1
  • 7
  • 18
1
vote
1 answer

How to prevent stored proc from returning intermediate recordsets?

Problem context : I use VisualStudio 2008 and typed datasets, which offer an "easy" access to executescalar() Execute scalar returns the value of the first field of the first row of the first recorset (this last part being often omitted) The problem…
oldbrazil
  • 367
  • 4
  • 11
1
vote
1 answer

ExecuteScalar returns nothing from stored procedure

I have a simple stored procedure that returns the type_id (int) as an OUTPUT parameter using the type_name (varchar(100)) as the input parameter. When I execute the stored procedure in SqlServer, it works fine and returns the appropriate…
1
vote
1 answer

Returning 0 instead of the actual value

I use the same SQL query within SQLiteStudio 3.1.0 and it works with no issues using the same parameter that I pass in. When I use the same SQL and use the code below in my VB project it returns 0 instead of right value. Private Function GetData()…
1
vote
2 answers

ExecuteNonQuery() always returning -1

I'm creating a login application with C# and SQL Server. What my program does: it looks if the given username and password can be found in the database. If it can be found, ExecuteNonQuery() should return 1 (1 row found). If the combination doesn't…
Cihan Kurt
  • 343
  • 1
  • 5
  • 21
1
vote
5 answers

C# executescalar realy slow on big table

I have a problem with executescalar being real slow on a table with over 200.000 records. The method i use checks if an varchar exists in the table and returns a count to see if anything can be found: public static bool AlreadyQueued(string url) { …
R.hagens
  • 325
  • 4
  • 19
1
vote
2 answers

Access column name with ExecuteScalar in C#?

I have a stored procedure that returns 0 or 1 depending on certain outcomes. I often execute this procedure manually, so to have a description of the success/failure that's easily viewed in SSMS but still readable as 0/1 in code, I select the 0 or 1…
John Straka
  • 1,874
  • 5
  • 28
  • 49
1
vote
2 answers

.NET SqlCommand ExecuteScalar Is Always 0

C# SqlCommand.ExecuteScalar() seems to always result in an object with value 0. Using SQL Server 2012. This is happening with all stored procedures. Here is a very simple example: CREATE PROCEDURE [dbo].[sp_IsUnitPackaged] @Serial…
Solipcyst
  • 150
  • 1
  • 1
  • 11
1
vote
2 answers

How to check whether particular value in field in MySQL exists

I'm looking for code that will help me check a particular column in MySQL and return its value if it already exists. I'm working on ForgotPassword module, so when the user clicks "Forgot Password", a form appears that will ask the user to input…
Fvcundo
  • 95
  • 2
  • 3
  • 11
1
vote
1 answer

Why am I getting "Invalid Cast Exception" with this SQLite code?

I've got this code to get a count from a SQLite table: internal static bool TableExistsAndIsNotEmpty(string tableName) { int count; string qry = String.Format("SELECT COUNT(*) FROM {0}", tableName); using (SQLiteConnection con = new…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
1
vote
4 answers

how to convert row value from sql server to string in c#

I have a method like this private string AccountCreation() { string accountId=""; using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(); …
1
vote
1 answer

ExecuteScalar() Limitations?

I have a GUID (varchar(50,notnull) in sql) That I am returning from SQL via ExecuteScalar() in VB I am storing that value in a string (max of 2gb) in VB I then run a select where GUID = Stored GUID When i run the program it looks like it trucates…
UPGRAYEDD
  • 415
  • 1
  • 8
  • 33
1
vote
2 answers

OledbConnection ExecuteScalar returns old value

I have a dropdownbox whenever the value changes in it, the textbox should get updated by executing the select query in the following method. But what happens is the query always returns the result of the first item in the dropdown box. When i…
0
votes
1 answer

Best practice for returning type from SQL Server to ExecuteScalar?

In C# SqlCommand - ExecuteScalar is : private object CompleteExecuteScalar(SqlDataReader ds, bool returnSqlValue) now let's go to SQL Server. If I want to return a value from the select (which goes to ExecuteScalar), e.g. : if record already…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792