executescalar

Looking for the best way to use ExecuteScalar()

♀尐吖头ヾ 提交于 2019-12-11 07:50:53
问题 This code works. It's based on some code I found on the internet. Can you tell me if the coding is the best way to get a scalar value and if there is a better way can you show coding samples? Dim objParentNameFound As Object TextBoxParentsName.Text = "" If TextBoxParentID.Text <> "" Then ' Display the parent's name using the parent ID. ' Dim strSqlStatement As String = "Select FatherName " & _ "From Parents " & _ "Where ID = @SearchValue" ' Set up the sql command and lookup the parent. '

C# cmd.ExecuteScalar(): “Cannot continue the execution because the session is in the kill state.”

喜夏-厌秋 提交于 2019-12-10 17:23:01
问题 Getting a weird exception from ExecuteScalar() that I cannot find any help for on the web: Cannot continue the execution because the session is in the kill state. I'm using SqlConnection/SqlCommand The command is a basic INSERT INTO... with 105 columns (and 105 parameters to set the column data) followed by a SELECT SCOPE_IDENTITY(); I've checked the connection string - it is correct and the connection is open. I'm not even sure what this error is telling me to know where to start looking on

Run multiple commands in one ExecuteScalar in Oracle

邮差的信 提交于 2019-12-10 13:42:53
问题 I have a batch of sql statements such as ... insert into.... ; insert into.... ; delete .........; etc When i try to execute them against oracle it gives me this error (ORA-00911 Invalid Character) now i can understand that this is because of the semicolon between the statements, i tried this on SQL Server and it worked but in Oracle no luck so far. Is there a way to run multiple statements against oracle by using the ExecuteScalar or some other function? DUPLICATE : How can I execute

What is a “Scalar” Query?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 01:30:37
I am using LLBLGEN where there is a method to execute a query as a scalar query . Googling gives me a definition for scalar sub-query , are they the same ? A scalar query is a query that returns one row consisting of one column. For what it's worth: Scalar subqueries or scalar queries are queries that return exactly one column and one or zero records. Source Aslam Khan A scalar method is used for aggregate functions such as max, min, sum, avg and so on. Whenever you want to return a single value after execute the query. 来源: https://stackoverflow.com/questions/20424966/what-is-a-scalar-query

Display SQL query result in a label in asp.net

こ雲淡風輕ζ 提交于 2019-12-01 09:07:48
I'm trying to display the SQL query result in a label but it's not showing. This is my code: string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' "; SqlCommand showresult = new SqlCommand(result, conn); conn.Open(); showresult.ExecuteNonQuery(); string actresult = ((string)showresult.ExecuteScalar()); ResultLabel.Text = actresult; conn.Close(); Need help please. Thanks! Try this one. string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' "; SqlCommand showresult = new SqlCommand(result, conn); conn.Open(); ResultLabel.Text = showresult

Can you use cmd.ExecuteScalar when the sproc uses RETURN @value

十年热恋 提交于 2019-12-01 05:31:33
Can you use int blah = Convert.ToInt32(cmd.ExecuteScalar()); When the sproc's last statement does: RETURN @value I can only get it to work if it does: SELECT @value Also, this gives me a object null exception: int blah = (int)cmd.ExecuteScalar(); isn't convert.toint32 and (int) the same thing but one is a wrapper of the other? No, you cannot. The ExecuteScalar() method is designed to return as single value that is returned in a result set. Basically, the value in the first column of the first row returned. To get the return value, you need to add a parameter to your SQLCommand object. Use the

Can you use cmd.ExecuteScalar when the sproc uses RETURN @value

扶醉桌前 提交于 2019-12-01 03:37:04
问题 Can you use int blah = Convert.ToInt32(cmd.ExecuteScalar()); When the sproc's last statement does: RETURN @value I can only get it to work if it does: SELECT @value Also, this gives me a object null exception: int blah = (int)cmd.ExecuteScalar(); isn't convert.toint32 and (int) the same thing but one is a wrapper of the other? 回答1: No, you cannot. The ExecuteScalar() method is designed to return as single value that is returned in a result set. Basically, the value in the first column of the

ExecuteScalar returns null or DBNull (development or production server)

混江龙づ霸主 提交于 2019-11-28 11:10:51
I'm trying to add a column to an existing DataRow in C#. Afterwards the column will be filled with a single value from my database. DataRow dr already exists and column "COLNAME" also exists. comTBP is my SqlCommand . dr["COLNAME"] = Convert.ToInt32(comTBP.ExecuteScalar()); This all works fine if there is a value in my database and ExecuteScalar() can get that value. If I test this code on my development server (local) it also works if ExecuteScalar() return null or DBNull and the value of my new column is 0. But the problem appears if I deploy my code to the production server. If I do

Int32.TryParse() or (int?)command.ExecuteScalar()

纵然是瞬间 提交于 2019-11-28 02:37:13
问题 I have a SQL query which returns only one field - an ID of type INT. And I have to use it as integer in C# code. Which way is faster and uses less memory? int id; if(Int32.TryParse(command.ExecuteScalar().ToString(), out id)) { // use id } or int? id = (int?)command.ExecuteScalar(); if(id.HasValue) { // use id.Value } or int? id = command.ExecuteScalar() as int?; if(id.HasValue) { // use id.Value } 回答1: The difference between the three performance wise is negligible. The bottleneck is moving

ExecuteScalar returns null or DBNull (development or production server)

走远了吗. 提交于 2019-11-27 05:59:35
问题 I'm trying to add a column to an existing DataRow in C#. Afterwards the column will be filled with a single value from my database. DataRow dr already exists and column "COLNAME" also exists. comTBP is my SqlCommand . dr["COLNAME"] = Convert.ToInt32(comTBP.ExecuteScalar()); This all works fine if there is a value in my database and ExecuteScalar() can get that value. If I test this code on my development server (local) it also works if ExecuteScalar() return null or DBNull and the value of my