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

SqlCommand and error: The left-hand side of an assignment must be a variable, property or indexer

I've got a little problem. In my program i need a list of SqlCommand objects. So there is a piece of code: List commands; int i = 0; foreach (string komenda in komendy) { commands.ElementAt(i) = new SqlCommand(komenda,…
user2229474
0
votes
2 answers

SQLCommand Fails When Connection Parameter is Not Set

I am having an interesting time using the Statement below that reads like this SqlCommand RiskRevalCommand = new SqlCommand("select * from CreditAdmin.dbo.CreditData_Test"); I took the SQL statement straight from a query in SQL Server…
jth41
  • 3,808
  • 9
  • 59
  • 109
0
votes
1 answer

Update sql command in vb.net flaws?

i have this code made by myself researching, it returns no error, it update(s) some of the data entered in textboxes but not all the fields i check the codes near the field that is updating to compare it to the textboxes that do not update. but i…
ivandinglasan
  • 384
  • 4
  • 15
  • 29
0
votes
3 answers

How to use executeScalar() inside executeReader()in asp.net using C#

I am getting error : "There is already an open DataReader associated with this Command which must be closed first." Code is as follows : I am generating dynamic table using 1 table & in every row of that table I want sum calculations from…
Nishant SB
  • 67
  • 2
  • 16
0
votes
1 answer

asp.net sql for "top 10 ordered in ascending order by the items within the top 10"

I need to use a database using ASP.NET and to take the top 10 items and sort them in ascending order within the top 10. I have used combinations of the following and have not got them to work: TOP 10 [rows] LIMIT (not supported) ORDER BY [rows]…
user963070
  • 629
  • 2
  • 19
  • 24
0
votes
3 answers

Data reader has rows but not populating combobox

I have this piece of code that is not populating combobox from datareader. I have done all kinds of checks and confiirmed that the database is connecting and the query is also correct. Databaseconnections is a module where I have declared all my…
0
votes
3 answers

Selecting specific data based on multiple conditions

I need some help constructing a SQL command for a database query. The database has 5 columns: Date(string) Name(string) number(int) There can be multiple entries for each date, name, and number. I want to SELECT only one row for each date and…
S1r-Lanzelot
  • 2,206
  • 3
  • 31
  • 45
0
votes
4 answers

Optimize SQL UPDATE statement/SqlCommand

I have the following statement: UPDATE Table SET Column=Value WHERE TableID IN ({0}) I have a comma delimited list of TableIDs that can be pretty lengthy(for replacing {0}). I've found that this is faster than using a SqlDataAdapter, however I…
user2097234
0
votes
1 answer

Passing a sqlcommand as a parameter. Throws invalid object error even if the object exist in the database

I have a problem with the following code. Please help. What I am trying to do is pass a sqlcommand to a function which then returns a dataset. The function 'Get data' takes sqlcommand as a parameter. This function is in class 'DatabaseUtilities' …
Abhishek Singh
  • 111
  • 2
  • 3
  • 10
0
votes
3 answers

List all data in sql table, row by row

I am trying to list all data in a table, but it only returns the first row, it doesn't loop the whole table. i need to return the data as strings, because I will use it in a ASMX web service. And the xml schema only returns the first row
user2053451
  • 7
  • 1
  • 7
0
votes
1 answer

NormDist & Square Root calculation in SQL

Please check the below screenshot for data classification. Just wondering is there any easy way to calculate NORMDIST, SQRT & PRODUCT using SQL commands just as like as I did below to calculate the AVG & VAR. Please note the below code I was using…
Kerry
  • 35
  • 2
  • 9
0
votes
3 answers

Issue with calling two methods in data access method

I have this method: public bool ActivateUser(string username, string key) { var user = this.GetUser(username, true); if (user != null) { if (user.NewEmailKey == key) { …
1110
  • 7,829
  • 55
  • 176
  • 334
0
votes
1 answer

I have an enigma in my method , VALIDATE and INSERT code

This is my INSERT code : Dim _cmd as new SQLCommand() Private Sub _btAdd_ANA_GRUPO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _btAdd_ANA_GRUPO.Click _resultCMD = 0 'Por cada linha da grid analises For Ro…
Flavius69
  • 18
  • 7
0
votes
2 answers

Bind the Data to DataGridView in C#

I have a table with ID and a Name column i want to show the one ID and Name in a DataGridView For Example in Textbox when i enter ID and click search button the datagridview shows the specifc record. In Search Button I have following Code but it…
Saima Maheen
  • 134
  • 3
  • 4
  • 11
0
votes
3 answers

Create linked server with instance name that contains special characters using c#

I have a stored procedure that creates a new linked server. The problem is that my InstanceName is "my-pc" (contains "-"), and therefore the LinkedServer is not generated correctly. My guess is that there is a problem in the way I pass the…
Inbal
  • 909
  • 2
  • 28
  • 46