Questions tagged [sqlcommand]

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

SqlCommand is a class in the .NET Framework whose instances represent a SQL statement to later be executed against a SQL Server database.

General syntax:

SqlCommand is instantiated with a query string and a connection. In C#:

SqlCommand cmd = new SqlCommand("select CategoryName from Categories", con);

Reference

SqlCommand on MSDN

919 questions
-2
votes
1 answer

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 API response is in the JSON format like…
user4912134
  • 1,003
  • 5
  • 18
  • 47
-2
votes
1 answer

error problem(the current name doesn't exist in the )

private void btnSave_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=LoginDB;Integrated Security=True"); con.Open(); SqlCommand commamd = new SqlCommand("insert into…
-2
votes
1 answer

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 the method runs with a different value until all…
banjo
  • 7
  • 3
-2
votes
1 answer

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, hashedPassword FROM [IO].[Users] WHERE username =…
-2
votes
1 answer

Compare two tables for a matching value from the respective columns and identify records missing

I have two tables and data like below: I want to compare two table's columns "Type and MatchType" and identify the Ids of first table where Type is missing in MatchType. "Type" and "MatchType" are the only common column in both tables in case if we…
Jasmine
  • 5,186
  • 16
  • 62
  • 114
-2
votes
1 answer

How to specify ReadOnly query in C# using SqlCommand()

I'm using C# with .NET SqlDataReader(), SqlConnection(), SqlCommand() and .ExecuteReader() classes. In vbScript, I can open RecordSets like this: rs.open cSQL, cn, adOpenForwardonly, adLockReadonly The rs.open statement can be given arguments to…
KWallace
  • 624
  • 7
  • 15
-2
votes
2 answers

Insert into data to database Error Parameters

I want to insert my DataGridView datas to my database i used parametrs these are my database fileds CREATE TABLE [dbo].[Tbl_Order] ( [Name] VARCHAR (50) NULL, [Price] INT NULL, [Quantity] INT NULL, …
-2
votes
1 answer

MySQL to find the number of employee(s) for each month

This is the table named employee. This is the question and sample output SELECT MONTH(EMP_HIREDDATE) AS “Hire Month”, COUNT(EMP_NUM) AS “No Of Employee” FROM EMPLOYEE GROUP BY EMP_NUM; The above command doesn't return the desired output. I…
zZzZ
  • 141
  • 2
  • 3
  • 10
-2
votes
1 answer

System.InvalidOperationException: 'There is already an open DataReader associated with this Command which must be closed first.'

ps : i tried to close connexions and datareaders but it didn't work , also tried the previous solutions here but still got the error i even separed the connexions and it didn't work as well what i'm trying to do here is to read an id from a table…
mod money
  • 1
  • 2
-2
votes
1 answer

Transaction not set

For some reason, SqlCommand.Transaction is not getting set. The code that sets it is definitely getting called (verified in debugger), but after the property is set, the property is still null. Here's the code... cmd.Connection = cmd.Connection ??…
Brian
  • 37,399
  • 24
  • 94
  • 109
-2
votes
1 answer

Replace a List with an array

I have the following method which I show below: public static string loadLista(string pStrOp) { System.Data.SqlClient.SqlConnection conn = new…
-2
votes
2 answers

MYSQL- command for copy value in column with same id

i need help to create the right MySQL command. As you can see in attachment , i need to copy string from column value with attribute_id 78 in column value with attribute_id 77 WHERE the entity_id is the same. can anyone help me write the right…
Emanuele
  • 87
  • 1
  • 9
-2
votes
1 answer

SqlConnection and SqlCommand with using statement

I have a connection to a database set up like this to call a stored procedure. I am just wondering if this is the best way to do this. I have two using statements one for the sqlConnection and one for the sqlCommand (which I am not really sure if…
psj01
  • 3,075
  • 6
  • 32
  • 63
-2
votes
2 answers

How does SqlCommand with parameters work?

public string InsertStudent(Student student) { string message = ""; SqlConnection connection = new SqlConnection(connectionString); string query = "insert into Students values(@regNo, @name, @email, @departmentId)"; SqlCommand…
-2
votes
2 answers

Trapping and throwing errors when using ExecuteNonQueryAsync which returns Task

When I do the following, I get a warning that not all code paths return a value if the catch block doesn't return an int; when that catch block returns an int, the capturedException test for null becomes unreachable unless it is placed inside a…
Tim
  • 8,669
  • 31
  • 105
  • 183