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
0 answers

How do I find the source of a SqlException (1205) Deadlock?

I'm dealing with a fairly large-scale C# application which occasionally hits a SQL Server deadlock. I can't figure out what's causing it. My bandaid solution for now is: (1) Catch the SqlException. (2) See if the error code is 1205 (i.e.…
Chad Decker
  • 5,997
  • 8
  • 27
  • 31
2
votes
4 answers

SQL Update Column By Adding A Number To Current Int

Simple enough, I can't figure out how to add (that's +) an integer from a textbox to the integer in the SQL Field. So for example, the SQL Field may have '10' in it and the textbox may have '5' in it. I want to add these numbers together to store…
user3224987
  • 83
  • 3
  • 12
2
votes
3 answers

Pass string array as parameter in SQL query in C#

In my application written in C# , I am writing a SQL query. Following is the query SELECT [Resource No_] where [Resource No_] In (@resources) @resources is user input parameters having one or more that one strings. My query is failing without…
user2739679
  • 827
  • 4
  • 14
  • 24
2
votes
9 answers

C#-SQL: How to execute a batch of StoredProcedure?

Edit: My problem is not a problem anymore: I have redo my performances tests and I have do a fatal stupid error: I had forget a x1000 to get seconds from milliseconds :/ Sorry for that guys. For info: - I do some 1900 updates per second from my…
2
votes
3 answers

using the same instance of SQLCommand more than one time in the same code for more than one query?

I have question about using why i can not use the same instance of SQLCommand more than one time in the same code? I tried the code down here and it runs good for the gridview but when i changed the query by using cmd.CommandText() method it keeps…
Max Byan
  • 21
  • 4
2
votes
1 answer

How can I increase the speed of many insert statements?

I have a .NET project that is receiving data, processing it, and then writing it to a SQLServer database. Let's say I have the following code. Private Sub InsertRecord(val1 As Integer, val2 As Integer, ByRef dbConnection As …
2
votes
6 answers

run multiple SqlCommand and ExecuteNonQuery

I am trying to run multiples SqlCommand in the same connection, but for some reason the program will stop at the second command.ExecuteNonQuery(); Here is my code : string queryString = "SELECT DISTINCT Titre from infosHoraire where…
Exia0890
  • 441
  • 6
  • 21
2
votes
1 answer

GROUP BY issue when SELECT to dataGridView from 2 tables

With little help of you I made this two QUERY. I posted pictures so you can see that in green squares are empty values which I would like to see and in red squares are values which I wouldnt like to display. Variable vyberradek inserts values for…
Blaze M
  • 200
  • 4
  • 16
2
votes
2 answers

MYSQL and random characters messing it

This salt messing up my SELECT command: p‚ÙÕ†¤éÿ5xÃø¤ü¥–ä™m›|§Éá\0yå–e decoded output: p‚ÙÕ†¤éÿ5xÃø¤ü¥–ä™m›|§Éá\0yå–e Without salt: mysql> SELECT userid,…
Alice
  • 701
  • 1
  • 5
  • 17
2
votes
2 answers

How to extract the Sql Command from a Compiled Linq Query

In normal (not compiled) Linq to Sql queries you can extract the SQLCommand from the IQueryable via the following code: SqlCommand cmd = (SqlCommand)table.Context.GetCommand(query); Is it possible to do the same for a compiled query? The following…
Andrew Harry
  • 13,773
  • 18
  • 67
  • 102
2
votes
3 answers

SqlCommand object - set it and forget it?

I'm using SqlClient.SqlCommand object to run a few stored procs on my db. Normally when I run these manually via Query Analyzer they take up to 15 minutes to complete. So obviously when I run them using the SqlCommand object I get a SqlCommand…
fieldingmellish
  • 1,473
  • 3
  • 16
  • 21
2
votes
2 answers

In what situations is the prepare method of a SqlCommand object useful?

Does any body know that in what situations the prepare method of an ADO.NET SqlCommand Object is useful?
odiseh
  • 25,407
  • 33
  • 108
  • 151
2
votes
1 answer

SqlCommand ExecuteNonQuery throws OutOfMemoryException

I have problem with executing Sql that in fact is simple call of stored procedure on SqlServer. Consider below Sql Stored Procedure: CREATE PROCEDURE InfiniteLoop AS BEGIN DECLARE @ixi NUMERIC(38) = 0 DECLARE @i…
pjozwiak
  • 71
  • 1
  • 8
2
votes
1 answer

start two SqlDependency on same sqlconnection but different sql commands

I build some service that on start open two threads, each one start SqlDependency with same sql connection but the command its different. Its possible? its seems to working, but after some will when the on change event need wake up its…
Daniel Tshuva
  • 483
  • 4
  • 12
2
votes
3 answers

SqlDataReader and SqlCommand

I have the following code. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { connection.Open(); SqlCommand select = new SqlCommand("SELECT RTRIM(LTRIM(PART_NO))…
Stuart
  • 1,544
  • 5
  • 29
  • 45