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
-1
votes
1 answer

SqlCommand that inserts data has no effect

I am trying to insert data into an existing Microsoft SQL Server 2014 table using VB.NET 2017. The code does not give me any errors, but it does not insert the record either. Right now I just want to get it to where it alters data, without worrying…
-1
votes
1 answer

Parse date to SQL when not in stored procedure

I am trying to parse dates to SQL but the command appears to ignore parameters: private void updateTasksDGV(DateTime? start, DateTime? end) { if (start == null) { string query = "select * from CRS_Diary where…
-1
votes
1 answer

SSIS - How to insert into OLE DB destination using SQL command while the source is flat file?

I want to know how to insert value in SQL Server database with the flat file source in SSIS using SQL command. I've done inserting it using table view, now i have to insert it using SQL command
-1
votes
1 answer

How to convert sqlDataReader to Task async

I have the following code-can anyone please tell me if I can make this a async Task public MDTO GetIe(MDTO dtoItem) { string[] Tables = new string[] { "C", "CValue", "SP", "Ar", "P", "CR", "QC", "SR" }; using (SqlConnection…
klkj898
  • 31
  • 5
-1
votes
2 answers

SqlCommand doesn't UPDATE and DELETE database when used in ASP.NET

I am having trouble with UPDATE and DELETE data in database when working with ASP.NET web form, the code work well with Windows form so I don't know what I did wrong. The code is suppose to update the Gridview with new edited data but when I click…
aukxn
  • 231
  • 1
  • 4
  • 8
-1
votes
1 answer

error Incorrect syntax near in c#

This statement gives the following error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect syntax near ','. Note: My table has 22 fields thanks for your…
-1
votes
1 answer

Deleting SQLCommand throwing inadequate exception

I have virtual dataGridView which displays all values in table by Just-In-Time method documentation here. My view has more computed columns, so I use it only to show data and then only delete by single SQLCommand. The problem comes when I am…
Hynek Bernard
  • 744
  • 1
  • 11
  • 30
-1
votes
1 answer

Parameters to SqlCommand and SqlDataAtapter

Have been working always with SQLDataAdapter and Fill command for data fetching querys and with executenonquery for insert, update, delete ones. I'm having a problem and can{t figure out what am I doing wrong. I have a DataTable bind to a RadGrid.…
TikalDog
  • 1
  • 2
-1
votes
3 answers

SQL Server parameterized query not setting bit value in target table

So I have a stored procedure with these parameters: ALTER PROCEDURE [dbo].[usp_insertOrUpdateTimeMilesNote] @id int, @ADID varchar(10), @projectId int, @taskId tinyint, @hours tinyint = 0, @minutes tinyint = 0, @miles…
tolsen64
  • 881
  • 1
  • 9
  • 22
-1
votes
1 answer

Execute multiple simultaneous SqlCommand.ExecuteNonQuery() and be notified when they finish

I have a set of SQL commands that don't return a query, only the amount of affected records. They run in different servers. They can run simultaneously, I don't need to wait one finish to start another. I'm developing a C# app, I'd like to execute…
Hikari
  • 3,797
  • 12
  • 47
  • 77
-1
votes
1 answer

Why is select scope_identity() returning 1 for SQL query?

I am using SQL query to with SELECT SCOPE_IDENTITY() in sqlcommand. here is my code: SqlCommand cmd = new SqlCommand("INSERT INTO tbl_Supplier(Supplier_Name,Supplier_Address, Supplier_PhoneNo,Supplier_City,Supplier_Remarks) VALUES('" +…
Iqra
  • 129
  • 1
  • 2
  • 11
-1
votes
1 answer

Insert new record with composite primary key, which consists of two foreign keys from different tables

Please help me figure out how to Insert new record with composite primary key, which consists of two foreign keys from different tables. I am working in C#, WPF if that matters. I have three tables: Sales, SaleItem, Item. CREATE TABLE…
-1
votes
1 answer

ExecuteNonQuery is returning a -1 when the query is selecting records. Why?

I have cod in a button click that looks like this: private void button7_Click(object sender, EventArgs e) { using (SqlConnection connect = new SqlConnection(PubVars.connStr)) { string query = "SELECT * FROM Users WHERE username =…
Bob Gatto
  • 131
  • 8
-1
votes
1 answer

Why isn't my delete statement working?

cmd.CommandText = "DELETE * FROM dbo.DisplayData" cmd.ExecuteNonQuery() I have the following delete statement at the moment, it's throwing an error at me when it's executed "Incorrect syntax near '*'". What I'm trying to do is delete all the rows…
BoogaWooga
  • 108
  • 7
-1
votes
1 answer

I want to know how to add items from sql database to a ListView

This is my code here, I wanted to put this into a listview from sql database, it reads just one and puts just one item in listview, but I want to place all items from database into a listview. my Database have 8 attributes but this code shows only…
Selim
  • 11
  • 6