922 questions
0
votes
2
answers
97
views
Cross database querying of large dataset within .NET Console application
I am working on a project where I need to combine data from 2 different databases on the same server. I am using the System.Data.SqlClient library, utilizing SqlConnection and SqlCommand.
I have ...
0
votes
0
answers
49
views
How can I set an SQL query with set value? [duplicate]
I have this commad that where id=333 how can I attach a string that will automatically put 333 with a sql query
string constr = ConfigurationManager.ConnectionStrings["PTS_Metcom"].ToString()...
0
votes
1
answer
57
views
Transport-level error has occurred when receiving results from the server. (provider: tcp provider, error: 0 - no such file or directory)'
using (var command = new SqlCommand("INSERT INTO TMateriales (NumMateriales, CodMateriales, NamMateriales, IslocalPMateriales, IdCategries, IsDepoMateriales, MadMateriales, PriceMateriales, ...
0
votes
0
answers
81
views
'The SelectCommand property has not been initialized before calling 'Fill'. ' error
I'm trying to have a DataGridView in my Windows Forms showing data from the database, but it doesn't want to run.
namespace DentalClinicManagementSystem
{
class MyPatient
{
public void ...
-1
votes
1
answer
430
views
How to convert DbNull to an empty string in Dapper
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 ...
1
vote
1
answer
698
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 ...
1
vote
1
answer
84
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 ...
0
votes
0
answers
114
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 ...
-1
votes
1
answer
140
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)...
0
votes
4
answers
123
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:
0
votes
2
answers
166
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 ...
0
votes
1
answer
54
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:
...
0
votes
1
answer
90
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....
0
votes
0
answers
693
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 ...
-1
votes
2
answers
190
views
Query causing sql injection issue
Type entryEntityType = entry.Entity.GetType();
string tableName = GetTableName(entryEntityType);
string primaryKeyName = GetPrimaryKeyName(entryEntityType);
string deletequery = string.Format("...
0
votes
1
answer
2k
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 ...
2
votes
1
answer
76
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() ...
0
votes
0
answers
57
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, ...
-1
votes
1
answer
52
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 ...
0
votes
2
answers
238
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(...
0
votes
0
answers
109
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) ...
-1
votes
2
answers
351
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;...
1
vote
0
answers
73
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))
...
1
vote
1
answer
253
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 ...
-2
votes
1
answer
1k
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 ...
0
votes
1
answer
1k
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,
...
0
votes
3
answers
78
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 ...
1
vote
1
answer
140
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....
1
vote
1
answer
1k
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 ...
-1
votes
1
answer
617
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....
0
votes
1
answer
106
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....
0
votes
1
answer
120
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 ...
1
vote
1
answer
5k
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\...
2
votes
0
answers
360
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 ...
0
votes
2
answers
2k
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) ...
1
vote
1
answer
2k
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 ...
1
vote
4
answers
457
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 ...
-3
votes
2
answers
868
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 = ...
-1
votes
1
answer
253
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 ...
0
votes
1
answer
827
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(
...
0
votes
1
answer
798
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 = ...
0
votes
0
answers
64
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 ...
-1
votes
1
answer
134
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....
0
votes
2
answers
288
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 ...
0
votes
1
answer
48
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
-1
votes
1
answer
137
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 ...
0
votes
2
answers
90
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 ...
1
vote
1
answer
255
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 ...
1
vote
1
answer
564
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 ...
0
votes
0
answers
429
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 ...