922 questions
2
votes
1
answer
2k
views
'Must Declare the Scalar Variable' Error When Passing a Table-Valued Parameter to a Parameterized SQL Statement
In C# I'm trying to pass a DataTable as a parameter to an SQL statement. The code I have is below:
protected virtual void DoDeleteRecords(List<Guid> ids)
{
if (ids.Count > 0)
{
...
1
vote
2
answers
1k
views
How to insert Datetimepicker Value in SQL Server database in custom format dd/MM/yyyy
SqlCommand cmd = new SqlCommand("Insert into [f_present] Values (@faculty_id, @name, @designation, @gender, @date, @status, @remarks)", con.active());
cmd.Parameters.AddWithValue("@...
-2
votes
1
answer
50
views
error problem(the current name doesn't exist in the ) [closed]
private void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=LoginDB;Integrated Security=True");
con.Open(...
3
votes
2
answers
1k
views
SqlConnection/SqlCommand keeps database in use after Close and Dispose
I am trying to create a temporary database for the purpose of integration testing in Xunit, but when I try to drop the temporary database, I get an error:
Cannot drop database "TempDatabase_[...
0
votes
1
answer
48
views
Sending multiple info to SQL
I’m sorry about the nonsense question title, here is what i intended to asked:
in c#:
So i have a list that has integers(id’s),
and i have a query string:
myList //the list that has id’s in it.
string ...
0
votes
1
answer
546
views
How to insert into Geography column using parameterized SQL
When I insert into a geography column with geography::STPointFromText, I have to dynamically build the column value, which ends up causing a SP:CacheMiss. My SQL cache is littered with singleton ...
-3
votes
1
answer
2k
views
How to execute SQL command using ADO.NET in C#?
First of all, I passed the connection string to SqlConnection as parameter:
SqlConnection con = new SqlConnection("server=ZIKO_RED2486;database=Students;Integrated Security = true");
Then ...
0
votes
2
answers
2k
views
How to pass dynamic parameter from SQL query to the SqlCommand after user input on the SQL query
all. I am facing an issue on how to pass the dynamic parameter value from SQL query, that will be entered by the user into the textbox, to the SQL command to search on the parameter value on the ...
3
votes
2
answers
630
views
Why is my SqlParameter not being recognised?
I am getting this error:
System.Data.SqlClient.SqlException: 'The parameterized query '(@inputKarakterSoort varchar(8000))SELECT TOP 2 * FROM Karakter ' expects the parameter '@inputKarakterSoort', ...
2
votes
2
answers
2k
views
C# | Use parameter in SqlCommand query
I have this ASP.NET Core project and in my DAL I collect my data from my database, but I want the user to be able to type a type character (Karakter is character in Dutch) and the DAL should pick 2 ...
0
votes
1
answer
33
views
Adding '% into SQL Command
I have an SQL Query that i want to run throw my asp.net (WebForms) Project
The Query is:
SELECT COUNT([order]) FROM menu_orders_Finished
WHERE [order] LIKE '%EXAMPLE%'
What i'm trying to do ...
0
votes
2
answers
345
views
SQL Command string c#
I'm currently in the process of writing a small script that exports the event log of a program and writes it to a database. However, I am having problems with my SQL insert command. What am I doing ...
0
votes
1
answer
831
views
In VB.Net, how to repopulate a datagrid from scratch?
I have written a generic VB.net subroutine that populates a datagrid with the results of a query. The subroutine as one parameter, strQuery, which is a string that can translate to any valid SQL-...
-1
votes
1
answer
234
views
Why am I getting an exception telling me that I need to declare a scalar variable here (referencing a parameter in a query)? [closed]
I've got a parameterized query which I build up based on selection criteria the user chooses on a web page. For example, here is an example query string (completeQuery) that is built:
SELECT M....
1
vote
2
answers
4k
views
Is this the fastest way to add multiple rows to a SQL Server table
I have a general question that I have not found any answer to. I think it is important to ask this question so I know how to structure the whole application so I am on the right track from the very ...
0
votes
1
answer
1k
views
How to insert a row at a specific index in a SQL database table using C# [duplicate]
I have created a SQL database named: DateTimes.
The database is now filled in with this information seen on this image:
As seen in the DateTime column, we can see those DateTime values in ascending ...
0
votes
1
answer
274
views
SqlCommand.Parameters.Add not converting parameters when trying to do DELETE statement
I am doing an INSERT query to a db with the following code which works fine.
public int InsertPerson(Person person, out string errormsg)
{
SqlConnection dbConnection = new SqlConnection();
...
0
votes
0
answers
150
views
SQLCommand object having incorrect byte array
My .NET application uses SQLCommand to execute queries and the DB SPs.
In one such SP that also returns the SQL 'timestamp' and that is read as byte array into the application. This byte array is ...
0
votes
1
answer
442
views
What's the best method for using SqlCommand and SqlConnection objects in an ASP.NET project [duplicate]
I am about to publish my first website, and I am kinda worried about SqlCommand and SqlConnection objects, they take too much space in the memory and might really overwhelm the server.
What's the best ...
1
vote
0
answers
157
views
SQL Server : using command prompt doesn't display the Chinese character but SSMS does
I have a table with INSERT INTO ABC("1000", "短消息"), I am able to execute it with SSMS but not with sqlcmd as it is accepting it and the output is [1000, J'aime] but not the Chinese ...
0
votes
1
answer
720
views
Update Parent table from Child Table using SqlCommand
I have 2 tables:
WorkSchedule which has 2 columns WorkScheduleID and WorkScheduleStatus
WorkShiftBid which has 3 columns: WorkShiftBidID, WSBidStatus, WorkScheduleID (foreign key to WorkSchedule ...
0
votes
1
answer
71
views
How to use SqlCommand with included two queries
First question, I would like to implement two queries in one command.
What is the correct syntax that should I followed?
I tried this
SqlCommand cmd = new SqlCommand("BEGIN;" +
...
-1
votes
2
answers
1k
views
Create SqlParameter with name and type only (no value assigned)
I am having issue to use SqlClient to call some sql query with parameter declared but not assigned. The query I want to run is similar to below
DECLARE @ID int;
SELECT @ID = OrderId
FROM Orders
ORDER ...
2
votes
0
answers
507
views
Temp tables via SqlCommand from .NET application
I use following pattern to work with SQL Server temp tables from .NET applications:
Open the connection
Create a temp table (only with ad hoc command!!!)
Write a lot of data into it via ...
0
votes
1
answer
95
views
How can I use SqlCommand for searching data with multiple input
enter image description here
I have a datatable as shown in the screenshot, and I want to search a Plant and Panel Tog Number for showing a Group and Coordination.
At first I tried this:
SqlCommand ...
0
votes
2
answers
66
views
column not allowed here,
CREATE table Patient (
Pat_number Number (30),
file_no Number (30),
Id_Card_No Number (30),
Pat_name varchar(30),
Date_of_Birth Number (30),
Blood_symbol varchar(30),
);
...
0
votes
1
answer
58
views
Is it safe to mutate an instance of SqlCommand immately after a call to Execute*Async?
When is it save to modify a SqlCommand without modifying the query to be run?
For example, when I have
SqlCommand cmd = getCommand();
con.executeNonQueryAsync();
//later
modifyParameters(cmd);
is it ...
-2
votes
1
answer
77
views
Refering to view values one by one
I have the following code which establishing an SQL connection inside of a project I am working on. What I want to do is to create a for loop which contains a method and every time the loop repeats ...
0
votes
1
answer
160
views
How to query four points of MBR covering all city points in country: SQL SERVER
I will query four point of Minimum Bounding Rectangle covering all city in country on SQL Server. Now, I can only find POLYGON of a city in Thailand. This is my SQL command.
DECLARE @TH geometry
...
1
vote
2
answers
1k
views
How many concurrent statements does SqlConnection support
How many concurrent statements does C# SqlConnection support?
Let's say I am working on Windows service running 10 threads. All threads use the same SqlConnection object but different SqlCommand ...
-2
votes
1
answer
60
views
Retrieve two strings from a stored procedure result to strings
[SCHOOL WORK]
I have a stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [IO].[usp_selectUser] (@username varchar(50))
AS
BEGIN
SELECT passwordSalt, ...
0
votes
1
answer
694
views
Set Sql to Single User mode From C# and Create Admin User
I have a c# winform application which connects to a database and read data.
This database is used by another app also. I just executed a query from my app to read some data.
I don't have the user ...
1
vote
3
answers
185
views
How can I run two SQL commands with a single connection?
I need to insert data in one table and update id in second table using add button:
private void addButton_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("Insert Into ...
0
votes
1
answer
148
views
sql not a valid month error in sql command line
Actually I was trying to get all columns within a date range in Oracle db and I am successful in doing so in SQL Developer but when I execute the same code in SQL command line interface I get an error ...
0
votes
1
answer
44
views
Unable to Update Rows in a SQL Table
I have some code that inserts and updates data into a sql table. I use ExecuteScalar to check if a row already exists with the same UserName and DeviceId. If it exists, we run the update stored ...
0
votes
2
answers
2k
views
Using post to update existing records in a database
I'm writing an API controller that inserts and updates records in a table. I'm able to insert new items into the database pretty easily, but I'm having a hard time understanding how to update existing ...
0
votes
0
answers
161
views
Get at underlying executing query inside stored procedure using SqlCommand [duplicate]
Assuming i have a stored procedure (example as follows)
CREATE OR ALTER PROCEDURE test
AS
BEGIN
SELECT * FROM sys.tables;
WAITFOR DELAY '01:00'
SELECT * FROM sys.tables
END
GO;
and I ...
0
votes
2
answers
63
views
VB Win Form Issue Using SqlCommand
I am currently creating a win form based tool in Visual Studio 2019 that reads data from a SQL database. I am having difficulty when pulling a field from the form I am working in into the sqlCommand ...
0
votes
1
answer
124
views
error in code vb.net import data from access to sdf
enter image description hereI am using a SQL Server Compact 3.5 database file (.sdf) in vb.net
There was an error parsing the query. [Token line number,Token line offset,,Token in error,,]
Dim flag ...
1
vote
3
answers
1k
views
Incorrect syntax near 'GO' using SqlCommand
This interface appears every time I execute this code that you find below :
str1 = "USE [" + database + "];" + vbCrLf +
"GO" + vbCrLf +
" CREATE TABLE [dbo].[ARMSet] ([Id] Int IDENTITY(1, 1) ...
0
votes
0
answers
3k
views
Passing list of IDs to WHERE IN from C# code [duplicate]
Challenging issue you have encountered already ?
This is my challenge.
I have the query as follows - MSSQL Server 2017 calling from my C# application.
SQL
update slides set isBorrowed=0, ...
0
votes
1
answer
407
views
SQL Query String Works in SQL Server Management Studio, But Not in VB.net with SQLCommand.ExecuteReader
I have an ASPX page using VB.net code, and it is set up to run a series of SQL queries and populate a SQLDataReader with the results. Each SQL query is pulled from a specific field in a table within ...
2
votes
1
answer
245
views
How to convert SqlCommand query to use parameters built using concatenated strings including variables using ternary operators
this is my first question, hopefully I do things correctly. Also to preface, I'm a programming noob tasked with developing and fixing some code where I work since the programmer we've had until now ...
0
votes
1
answer
940
views
SqlDataAdapter.SelectCommand not returning the right result
I am just facing a problem with my code.
I want to select some data from a database using the SqlDataAdapter SelectCommand property.
My code looks like:
static SqlConnection sqlConnection;
static ...
1
vote
3
answers
131
views
Can you tell whats wrong with the SqlDataReader i returns "System.Data.SqlClient.SqlException: 'Must declare the scalar variable "@idorder"
Hi since I am using the using-statement, my disposable connections should be handled once it leaves the statement but my code is hard coupled in other methods in the program where I poll the db or ...
0
votes
1
answer
316
views
find a string value 'n/a' in all columns of a table
I would like to search in entire table, where the string is 'NA', 'na' or 'N/A'.
Actually, the value was supposed to be 'n/a' but it was mistakenly placed as 'NA', 'na' or 'N/A' by different ...
-1
votes
1
answer
194
views
passing columnname with a parameter SQLcommand
I've been googling something I dont really cant understand.
In short my problem is this;
When using this;
String sYear2 = "2020";
string query = @"Select decJan from Stats where intRecnum = (select ...
0
votes
2
answers
988
views
C# BulkCopy.WriteToServer Changing Values
I have a datatable that is created from and excel sheet. I am trying to SqlBulkCopy.WriteToServer. When I do so it converts my "Percent" value to 0 when my tables schema has type Decimal(38,0) for ...
0
votes
1
answer
732
views
Creating #temp table using SqlCommand.ExecuteNonQuery()
Hello I am trying to create a #temp table using SqlCommand.ExecuteNonQuery. When I execute the non query no error occurs, but also no table is created. If I try creating a normal table it works fine....
1
vote
2
answers
1k
views
System.Data.SqlClient.SqlException: 'Incorrect syntax near '='.' on Datatable and object
I've looked at a lot of similar questions on this site and elsewhere but none of them have helped me.
I'm trying to make a database connection with a query but I get the error
System.Data....