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

My stored procedure returns something, but sqlDataAdapter.Fill leaves datatable empty

Something stopped working in my application. I tested my stored procedure and it does return 3 rows (too big to repost here). At the output in Visual Studio it says afterwards: (1 row(s) affected) (3 row(s) returned) @RETURN_VALUE = 0 Finished…
Kasper Hansen
  • 6,307
  • 21
  • 70
  • 106
2
votes
1 answer

How to get some results mid query using SqlCommand

I am using SqlCommand to perform a query, however this query is very slow in general - taking about 50 seconds to complete - is there anyway I can read the results as they come in one by one? using (SqlConnection connection = new…
Alfie
  • 297
  • 1
  • 12
2
votes
1 answer

Dynamic SQL command not getting executed

I need to convert some tables as Temporal (System versioned) ones. For this purpose, I have written an SQL command to be executed in a dynamic manner. The query does not throw an error, but it doesn't execute the SQL command. It does not print the…
Kushan Randima
  • 2,174
  • 5
  • 31
  • 58
2
votes
2 answers

Web API to connect to SQL Server and return response in JSON

I am trying to create a Web API that queries the SQL Server and returns the response in a JSON. Below is what I am trying [HttpGet] public HttpResponseMessage Getdetails(string ROOM) { if (string.IsNullOrEmpty(ROOM)) { …
trx
  • 2,077
  • 9
  • 48
  • 97
2
votes
1 answer

Handle leak in C# ADO.Net Application

Here is a short code snippet to execute a query using ADO.Net using(SqlConnection objSqlConnection = new SqlConnection(sConnectionString)) { objSqlConnection.Open(); using (SqlCommand objSqlCommand = new SqlCommand(sSQLQuery,…
2
votes
4 answers

SQL query result to array/List

Following is the C# code for querying the DB to get the list of users id: int id; con = new SqlConnection(Properties.Settings.Default.ConnectionStr); con.Open(); id = 180; SqlCommand command = new SqlCommand("Select userid from UserProfile where…
Jeya Suriya Muthumari
  • 1,947
  • 3
  • 25
  • 47
2
votes
3 answers

SQL - how to replace a range of datetimes with a single, future datetime?

This is a basic SQL datetime question, but I don't want to mess my database up! For example, in a MySQL database, if I want to replace all datetime values between date X and date Y in a single column in one of my tables - what's the SQL command to…
Jamison
  • 2,218
  • 4
  • 27
  • 31
2
votes
4 answers

Disposing SqlCommand

Because SqlCommand implements IDisposable, I would normally approach an ADO query as follows. using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(query, connection)) { // Execute…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
2
votes
1 answer

C# ASP.NET Web Api Controller - Get all rows from a table using SqlCommand

I'm making a web api server that I need for a school project because we have to make several applications on different platforms to communicate through messages and the web api server has GET, POST and DELETE methods. Right now I have a GET method…
Lada1208
  • 57
  • 1
  • 5
2
votes
3 answers

C# SqlCommand query with update

I tried to find it. But I can't found exactly my answer. So I decide to ask this questions. I need your help. I want add value into table value without overwriting Debit, Score column. It will add current value. cmd = new SqlCommand("UPDATE Users…
2
votes
1 answer

How could I pass parameter to sqldataadapter?

I have tried to pass parameter a value, but what it returns is nothing. If I use a simple sql command without parameter I can retrieve all the data from my database. Here is my code: Public Shared Function RetrieveData() As DataTable …
Sophart
  • 67
  • 1
  • 10
2
votes
1 answer

Why is OLE DB Command trying to update the schema?

I have an SSIS data flow task that is taking lookup matched records and feeding them to an OLE DB Command component. When I run it I get an error that says: Error: 0xC0202009 at Data Flow Task, OLE DB Command [28]: SSIS Error Code…
2
votes
1 answer

Any one given this role should be able to assign privieleges to other ORACLE COMMAND LINE

The Question given in Past Exam was you need to give academic role the ability to select from, insert into and modify existing rows in Student table. Anyone given this Academic role should be able to Pass those privileges to other. write a…
Rohaitas
  • 84
  • 1
  • 12
2
votes
1 answer

Reading 200MB file from db throws Out Of Memory Exception

I am attempting to query the database and pull excel files that could be as large as 1 million rows (~200MB) stored as varbinary and pass it through a validator. Our build server has 6GB of memory and a load-balanced processor and during runtime…
Nathan Foss
  • 595
  • 1
  • 9
  • 34
2
votes
2 answers

F# best way to set up a SQLCommand with parameters

My F# program needs to talk to SQL Server. In one part I have something like this: let workFlowDetailRuncommand = new SqlCommand(query, econnection) workFlowDetailRuncommand.CommandTimeout <- 100000 …
user1443098
  • 6,487
  • 5
  • 38
  • 67