Questions tagged [sqlcommand]

Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database which is used in Microsoft .NET.

Filter by
Sorted by
Tagged with
-2 votes
0 answers
19 views

SELECT customer_id CASE WHEN first_name = 'Tnoy' THEN 'Tony' ELSE first_name END AS cleaned_name FROM customer_data.customer_name [closed]

I am receiving "Syntax error: Expected end of input but got keyword CASE at [3:2]" I tried performing the task as instructed and I keep receiving the same error. SELECT customer_id CASE ...
Margaret Perez's user avatar
-1 votes
1 answer
82 views

Dapper convert DbNull to empty string

I am refactoring some code that used reflection to map a SqlCommand to a model. The new code uses the Dapper framework and works perfectly fine: Public Shared Function GetModel(Of T As New)(cmd As ...
Vincent's user avatar
  • 2,081
1 vote
1 answer
104 views

How to show the backslash commands in PostgreSQL?

With \help or \h below, I could show the SQL commands as shown below: \help Or: \h postgres=# \help Available help: ABORT CREATE USER ALTER AGGREGATE ...
Super Kai - Kazuya Ito's user avatar
1 vote
1 answer
37 views

Chapter 4 case project

Create a view named HighBalance using the the patient number, last name, first name, street, city and zip code for those patients with a balance greater than $1,000. Display the data in the view Im ...
Skeeball 1987's user avatar
0 votes
1 answer
50 views

Getting values from C# SqlDataReader into an integer variable

I am using SqlCommand to run a simple query against my database: SELECT MIN(ID), MAX(ID) FROM DocumentImage Obviously the query should return one row with two columns a minID (1) and a maxID (...
BenStark's user avatar
0 votes
0 answers
70 views

C# Additional String Validation For .text

I'm trying to figure out on the proper way for the additional string validation. I have an SQL query below which is compiled on c#, detected by Checkmarkx application that the Row.Cells[2].Text is not ...
Lia Lucindia's user avatar
-1 votes
1 answer
62 views

Wrong output parameter read from T-SQL stored procedure [duplicate]

I have to read a value from a simple T-SQL stored procedure. When I test the procedure in SQL, it works fine. But when I try to read by a C# SqlCommand, it returns a wrong value that is always 0 (zero)...
Riccardo's user avatar
0 votes
4 answers
90 views

How to remove duplicate rows with the same column in SQL

I have the following table in SQL: I want to remove rows with the same id value. Which query in SQL should I use? The table should be as follows after the delete operation:
user's user avatar
  • 136
0 votes
2 answers
62 views

How can i write raw SQL commands in EntityFramework 6

I'm trying to do a raw SQL statement which resembles this DELETE FROM db.T0590_CODE_STRING WHERE IN (1,1,2,3,5) the values in the IN clause are from rowIds list so therefore I'm trying to use a ...
Bouyalife's user avatar
0 votes
1 answer
36 views

Adding variable in SQL command not working with Select statement

Code: x = int(id_[0]) select_query = "SELECT * FROM files WHERE id = %s" cursor.execute(select_query,x) results = cursor.fetchone() I am using mySQL in Python. This is the error I get: ...
Tamer Vassib's user avatar
0 votes
1 answer
72 views

C# string to number

I want to store to a column a value from string to number I have this part of code in c# //Order string refId = order.id.ToString(); ApplicationLogger.Write("order.date_created : " + order....
ΙΩΑΝΝΗΣ ΡΙΣΒΑΣ's user avatar
0 votes
0 answers
73 views

SQL Server throwing error on valid SQL - incorrect syntax near 'and'

I have a data transformation application where one of the first steps is for the user to paste in a valid SELECT statement. After it is verified, the app will execute it against their database and ...
Skattch's user avatar
  • 11
-1 votes
2 answers
127 views

Query causing sql injection issue

Type entryEntityType = entry.Entity.GetType(); string tableName = GetTableName(entryEntityType); string primaryKeyName = GetPrimaryKeyName(entryEntityType); string deletequery = string.Format("...
Radha's user avatar
  • 71
0 votes
1 answer
47 views

What is the best way to get rows of data and its datatypes?

Currently, I’ve been working to translate a whole table and put it into another table with same schema. Given: Since the table data rows are more than a thousand rows, it is quite hard to translate ...
choopau's user avatar
  • 2,249
0 votes
1 answer
702 views

How to pass list of guid as a parameter to a sql command

I need to filter a sql request by passing a list of id to , this is the command: var command = "select Software.Name as SoftwareName,SoftwareType.Name as SoftwareType from AssetManagement.Asset ...
A.HADDAD's user avatar
  • 1,829
2 votes
1 answer
52 views

Will a SqlConnection() declared before using it in a using() statement still close the connection when done? (C#/SQL Server)

In a situation like this: SqlConnection cn = new SqlConnection( ConfigurationManager .ConnectionStrings["AppConnection"] .ConnectionString ); using (cn) {...} Will the using() ...
KWallace's user avatar
  • 1,608
0 votes
0 answers
44 views

SqlCommand Time Out After Repeat (Simple) Queries in .NET / F#

I am running a relatively simple query using SqlConnection / SqlCommand / SqlDataReader. The code looks like the below. I have this inside of a function where I pass in a date to call this function, ...
Eugene's user avatar
  • 125
-1 votes
1 answer
41 views

Inserting a List of Data results in a connection error

I am trying to enter a list of data objects to my table using a loop. But during the loop, the logic abruptly stops with this error: There is already an open DataReader associated with this Command ...
Jay's user avatar
  • 4,933
0 votes
2 answers
154 views

SQLCommand AddWithValue - What am I doing wrong?

protected void gridOmniZone_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = gridOmniZone.Rows[e.RowIndex]; Int64 ID = Convert.ToInt64(...
user avatar
0 votes
0 answers
83 views

Sql injection while using @@TranCount instruction in SqlCommand

I have such code: private DbTransaction sqlTransaction = null; ... ... ... using (DbCommand command = new SqlCommand("SELECT @@TRANCOUNT")) { if ((int)command.ExecuteScalar() != 0) ...
Aleksandr Romanov's user avatar
-1 votes
2 answers
282 views

How can I fix the vb.net error "array bounds cannot appear in type specifiers"?

How can I fix the vb.net error "array bounds cannot appear in type specifiers" in the following code? Dim con As New SqlConnection("Data Source=localhost;Initial Catalog=WebAssignment1;...
Putu Widianingsih's user avatar
1 vote
0 answers
59 views

SQL Command executes, SQL Statement viewable in SQL Profiler returns rows, DataReader has no rows

I'm working on an application that uses C# to do a search like so: using (SqlCommand cmd = new SqlCommand("[dbo].[usp_Search]", commercialConn)) ...
awimley's user avatar
  • 692
0 votes
1 answer
105 views

Is it correct to not dispose of SqlCommand like the example in Microsoft documentation?

The Microsoft Documentation for the SqlCommand class gives the following example code which does not dispose of the SqlCommand. SqlCommand inherits from DbCommand which implements IDisposable. Common ...
Aaron Anodide's user avatar
-4 votes
3 answers
568 views

Error during SQL Update: "Incorrect Syntax Near '1'" [closed]

I have an application that I'm trying to use to make some database updates. However, whenever I try to save, I get this error message: Incorrect Syntax Near '1' What does this error message mean, ...
alexa torrento's user avatar
-2 votes
1 answer
940 views

Unable to insert data from the JSON in to the SQL server table

I am trying to create a SSIS package that makes a call to the REST API and insert the responses into the Azure SQL server table. For this I am using the script task and ADO.NET connection manager. The ...
user4912134's user avatar
  • 1,013
0 votes
1 answer
562 views

How do I add a Calculated [bit] Data Type field to a SQL Table?

I would like to add a [bit] field that is calculated from a Boolean [int] field SQL Table looks as follow: CREATE TABLE [dbo].[AutoIndexBoolean]( [RowID] [int] NOT NULL, [Boolean] [int] NULL, ...
Evan's user avatar
  • 3
0 votes
3 answers
74 views

LINQ select duplicate object values

I have a table: Name | account info| AccountNumber -----| ------------| ------ abc | IT | 3000 bdc | Desk | 2000 sed | Kitchen | 3000 afh | work | 4000 hsfs | home ...
Jeff's user avatar
  • 115
1 vote
1 answer
86 views

Linq query С# ASP.NET Core

I'm executing a sql script using: SqlCommand command = new SqlCommand(sqlQuery, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if(reader.HasRows) { while(reader....
Jeff's user avatar
  • 115
1 vote
1 answer
464 views

Using Updlock and Readpast in C#

I am looking to concurrently read and update records from a database. At this point, I have a sample program set up that grabs records from a database with a certain status. I am aiming for the rows ...
noahsrc's user avatar
  • 13
-1 votes
1 answer
527 views

Syntax error (missing operator) in query expression in C# script task in SSIS

I get this error: System.Data.OleDb.OleDbException (0x80040E14): Syntax error (missing operator) in query expression ''O'Brien','O'Brien''. at System.Data.OleDb.OleDbCommand....
Dinesh Kumar's user avatar
0 votes
1 answer
98 views

SqlDataReader and SqlCommand in C#

private void button1_Click(object sender, EventArgs e) { object functionReturnValue = null; using (System.Net.WebClient client = new System.Net.WebClient()) { System.Collections....
kenluffy32's user avatar
0 votes
1 answer
75 views

SQL Server query: Uncaught TypeError: content is null

What I am trying to do, is query from my database and populate the columns inside my Index.cshtml. Below is my code: This is from my HomeController: SqlConnection con = new SqlConnection("Data ...
yongchang's user avatar
  • 523
0 votes
1 answer
3k views

How to fix input string was not in a correct format in sql on C#?

public static String AccountNumber; public static double oldBalance, newBalance; SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\CSharp\ATM\...
Ranvoxrat's user avatar
2 votes
0 answers
240 views

Fastest bulk deleting using LINQ-to-SQL

I have an old solution running on LINQ-to-SQL (DMBL), where I want to delete a large amount of rows based on id's (incl. a lot of referenced objects). But the traditional way of using DeleteOnSubmit ...
baddaydaddy's user avatar
0 votes
2 answers
917 views

Execute SqlCommand without providing values to parameters

I have a stored procedure in my database: ALTER PROCEDURE [dbo].[SP_UPDATE_PARAMS] (@ELEMENT NUMERIC (10), @NUM_PARAM_OP_DINT NUMERIC (3,0) OUTPUT, @NUM_PARAM_OP_REAL NUMERIC (3,0) ...
LSG's user avatar
  • 127
1 vote
1 answer
1k views

Execution timeout expiry when executing a stored procedure which uses a table valued parameter

I have a stored procedure which uses a table valued parameter (tvp). In my application, I use a datatable as a SqlParameter to match the tvp structure. The problem is that it sometimes takes 25 ...
Conorou's user avatar
  • 31
1 vote
4 answers
319 views

How do I reverse the query affect if any of the other statement fails among several statements?

var sqlCommand= "@ DELETE FROM table1 WHERE id = @Id DELETE FROM table2 WHERE id = @Id "; var isDeleted = db.Database .ExecuteSqlCommand(sqlCommand, new ...
Fanny Hunayn's user avatar
-3 votes
2 answers
606 views

What is the reason for my SqlException: Incorrect syntax near '='? [closed]

This is my code: private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "data source = LAPTOP-ULT25NKH; database = ...
amandi yalapola's user avatar
-1 votes
1 answer
217 views

Try to load images (categorized by city) from local DB to flowLayoutPanel

I'm trying to build a Form that can insert images to local DB and load them to flowLayoutPanel. Here is the layout of my form, I insert images in 'admin' tab (pic.1). In 'Browse Photos' tab I try to ...
YS Chang's user avatar
0 votes
1 answer
600 views

Read multiple values returned by multiple SELECT from a SP

I have this SP (extremply simplified for exhibit) SELECT colA, colB, colC INTO #MyTable select COUNT(*) from #MyTable On the C# side, I have int total = 0; var command = _context.CreateStoreCommand( ...
user2687153's user avatar
0 votes
1 answer
391 views

Add column and table name as parameters in SqlCommand like "SELECT @col from @table" queries

I'm working on an application, reading tables in an MS-SQL database. Normally this way of working is fine: sqlCommand.CommentText = $"SELECT {Col_Name} FROM {variable}"; sqlReader = ...
Dominique's user avatar
  • 16.3k
0 votes
0 answers
53 views

SQL Command: Repeating input in command

I have an Excel worksheet with several queries, where I enter a date format several times per query. When I produce the data for May I input '2021-05-31' several times, and when I want to produce data ...
Attp30998's user avatar
-1 votes
1 answer
107 views

SQLCommand Error on Visual Studio Designer (WinForms)

On a C# project (.NET Framework 4.8) when I try to create a control SqlCommand using the designer I get the following error Failed to create component 'SqlCommand'. The error message follows: 'System....
CHRISTOS STAVRINOU's user avatar
0 votes
2 answers
230 views

If I use SqlCommand in a method as a parameter, does it block a SqlConnection dispose?

I'm having connection pool issues on my service (max reached), everywhere that I try to open a connection I wrap it on a using statement to dispose it correctly, but I think something is not allowing ...
qhart's user avatar
  • 29
0 votes
1 answer
38 views

SQL command for getting a specific pattern

I have a table sample with column 'observations': Please help with the SQL command to get the following 'cumulative multiplication' output: 2 6 30 300
Dynamo's user avatar
  • 51
-1 votes
1 answer
100 views

SqlCommand with where clause backslashes [closed]

There is a matching record in the DB for DESKTOP-123\\markj. When I execute the code in SQL Server Management Studio, it returns one record. DECLARE @User NVARCHAR(260) = 'DESKTOP-123\\markj' SELECT ...
MaxPowers's user avatar
  • 484
0 votes
2 answers
70 views

SQL command if sum = 0 by criteria

In my table I have Voucher, Dimension and Amount. Each Voucher is unique, and Dimension is usually similar per two Vouchers. There is also usually an identical positive and negative amount per Voucher ...
Attp30998's user avatar
1 vote
1 answer
141 views

c# If I pass a parameter in SqlCommand, like operator in sqlcommand doesn't work

Here's the query that I need to perform: SELECT COUNT(*) FROM Faq WHERE IdApplicazione = @IdApp AND (TestoDomanda LIKE '%search%' OR TestoRisposta LIKE '%@search%') I'm trying to perform it in C# by ...
AutomationNeeded's user avatar
1 vote
1 answer
255 views

Use SqlCommand in .net to modify database using parameters

I have to modify a SQL Server database dynamically, depending on some inputs. What I wanted to do is to generate the modification commands and then execute them. And, to avoid SQL injection, I wanted ...
xecollons's user avatar
  • 568
0 votes
0 answers
342 views

Conversion failed when converting date and/or time from character string; with SQLCommand.CommandText and SQLCommand.Parameters.AddWithValue

I'm trying to insert data into my SQL Server 2014 database. I wrote the SQL query with the @parameters and used the SqlCommand.Parameters.AddWithValue to parse the values, without worrying about SQL ...
M. Ulus's user avatar
  • 11

1
2 3 4 5
19