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

sqlcommand execute query not updating deleting and inserting

Hello i always use SQlcommand for non query but now something wrong i dont know what i have 3 buttons with operations update insert and delete but i created unique method for all 3 operations, the problem is it doesn't insert delete or…
0
votes
2 answers

For loop using in conjunction with an sqlcommand

i have an SProc which returns the avg of all columns between two times, ie 04:00 to 04:14. I want to have an option to return results for 24hr at that same interval (in this case the interval is 15mins. 04:14 - 04:00) So the results would look like…
Hans Rudel
  • 3,433
  • 5
  • 39
  • 62
0
votes
3 answers

SELECT SqlCommand

I know this is a simple question, but I can't get it to work. This is my query in my SqlCommand: SELECT * FROM zipcode WHERE city LIKE @prefixtext + '%' ; I only want 10 results, every other answer suggests SELECT TOP 10 * FROM zipcode WHERE…
Scott Selby
  • 9,420
  • 12
  • 57
  • 96
0
votes
5 answers

C# SQLCommand does not work

I have a WebService with the following Method: [ScriptMethod(ResponseFormat = ResponseFormat.Json)] [WebMethod] public string Login(string passwort, string email, string firma) { return LoginHelper.Login(passwort, email,…
Bashud
  • 266
  • 2
  • 8
  • 20
0
votes
4 answers

How to avoid accidentally closing an SQL Connection in Java?

Currently what i am doing for transaction management is: Connection connection = getConnection(); connection.setAutoCommit(false); updateTableX ( connection, ... ); updateTableY ( connection, ... ); connection.commit(); closeConnection(); I would…
Rakesh Juyal
  • 35,919
  • 68
  • 173
  • 214
0
votes
2 answers

NullReferenceException in SqlCommand.ExecuteNonQuery() after calling SqlCommand.Prepare()

I am running into a problem where a NullReferenceException is being thrown. Here is the code: using (SqlConnection connection = new SqlConnection(@"server=localhost\SQL2005;database=UintaTest;Integrated Security=SSPI;Connect Timeout=240")) using…
0
votes
2 answers

How to Converting SqlCommand Type To Int Type

I Want To Convert SqlCommand Result into Int Value How Can i Do that?? Please Help With That What I Have Tried IS Below: The stp_no in Table Have Set Identity Property. And I want To insert That Auto Generated Numbers into Another Table But It Shows…
mitul
  • 11
  • 1
  • 3
0
votes
1 answer

OpenSessionInView pattern, ADO and performance

We are using NHibernate with OpenSessionInView pattern for our AspNet webapp. Using ADO connection (SqlServer) we want to log in a different database every acces to pages. For that, do we need to open a connection at every "page load", execute the…
Francois
  • 10,730
  • 7
  • 47
  • 80
0
votes
3 answers

Using SQLCommand - Will it dispose of items passed to strings?

I'm doing some SQL connections with the 'using' command to dispose/close connections for me. If I pass items to a string from within the using command, will they remain once the connection is closed/disposed? If it does, what is the best way to make…
PipBoy
  • 1,127
  • 4
  • 11
  • 16
0
votes
3 answers

SqlCommand with parameters as a string

I have an application I need to create which, given some user input in the form of CSV, needs to parse and generate this CSV into multiple formats. One of these formats is a series of SQL INSERT statements (as a string) for each line of CSV. (At…
daniel
  • 1,148
  • 1
  • 13
  • 20
0
votes
1 answer

Why is my program not connecting to the database?

I'm creating a database so I can store usernames and passwords. I have successfully created a DB on Microsft Visual Express C# 2010. My program seems to be working fine, and produces no error message, except that I'm not getting any feedback: it…
Adam
  • 45
  • 1
  • 7
-1
votes
1 answer

Wrong output parameter read from T-SQL stored procedure

I have to read a value from a simple T-SQL stored procedure. When I test the procedure in SQL, it works fine. But when I try to read by a C# SqlCommand, it returns a wrong value that is always 0 (zero). I have already other similar code that do the…
Riccardo
  • 11
  • 2
-1
votes
2 answers

Query causing sql injection issue

Type entryEntityType = entry.Entity.GetType(); string tableName = GetTableName(entryEntityType); string primaryKeyName = GetPrimaryKeyName(entryEntityType); string deletequery = string.Format("UPDATE {0} SET IsDeleted = 1 WHERE {1} = @id",…
Radha
  • 71
  • 8
-1
votes
1 answer

Inserting a List of Data results in a connection error

I am trying to enter a list of data objects to my table using a loop. But during the loop, the logic abruptly stops with this error: There is already an open DataReader associated with this Command which must be closed first. Here's my…
Jay
  • 4,873
  • 7
  • 72
  • 137
-1
votes
2 answers

How can I fix the vb.net error "array bounds cannot appear in type specifiers"?

How can I fix the vb.net error "array bounds cannot appear in type specifiers" in the following code? Dim con As New SqlConnection("Data Source=localhost;Initial Catalog=WebAssignment1;Integrated Security=True") con.Open() Dim command As SqlCommand…