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

c# Local Database insert into doesn't work

I tried too many times but insertion doesn't work! Please help me.. codes: SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"); conn.Open(); SqlCommand cmd =…
Mazlum Özdoğan
  • 219
  • 3
  • 14
-2
votes
1 answer

How can I add values found in a Database to a series of Dropdown Buttons?

I have an app which sends texts to clients, and I'd like to be able to provide a templating system for it; the completed code will fill a toolStripDropDownButton with values from my Database, providing a description from the database, then when the…
Reece
  • 89
  • 1
  • 10
-2
votes
2 answers

Collect data and display the data in a column label

How can I sum a column to the table without dataGridView and i'm using sql command method And my database is in SQL server 2008. I like this script
-2
votes
1 answer

How to convert Linq to SQLCommand

I have SQLCommand below but instead of writing SQL text inside method I would like to write entire SQL command in Linq to prevent Entities mismatch if POCO models are changed. Database.ExecuteSqlCommand("UPDATE [Order] SET [Credits] = @Credits…
Tomas
  • 17,551
  • 43
  • 152
  • 257
-2
votes
3 answers

; expected c# transfer and carry big string VS2012

I have CmdString = "insert into Team_table (name1, name2, result1, result2) (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)"; Whene I divide it in 2 columns by presssiin enter like CmdString = "insert into Team_table (name1,…
streamc
  • 676
  • 3
  • 11
  • 27
-2
votes
3 answers

Dynamic where clause in parameter

I am currently trying to build up the where clause of an SqlCommand. something similar to this myCommand.CommandText = "SELECT * " + "FROM TABLE1 " + "@whereClause"; //I build up the where clause with…
Rémi
  • 3,867
  • 5
  • 28
  • 44
-2
votes
3 answers

update command not working in asp.net c#

protected void Button1_Click(object sender, EventArgs e) { SqlConnection mycon = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=master;Integrated Security=True"); SqlDataAdapter myadp = new SqlDataAdapter(); …
-2
votes
1 answer

Best way to execute sql command in c#

I need to do some sql query against sql-server 2008 R2. The command is: C:> sqlcmd –S .\APPSDB 1> use Example_database 2> go 1> Select SiteName, SiteID, Platform, Description, AdminUser from dbo.ExampleInfo 2> go I want to develop a console…
ericyoung
  • 621
  • 2
  • 15
  • 21
-3
votes
2 answers

What is the reason for my SqlException: Incorrect syntax near '='?

This is my code: private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "data source = LAPTOP-ULT25NKH; database = college;integrated security = True"; SqlCommand cmd =…
-3
votes
1 answer

How to execute SQL command using ADO.NET in C#?

First of all, I passed the connection string to SqlConnection as parameter: SqlConnection con = new SqlConnection("server=ZIKO_RED2486;database=Students;Integrated Security = true"); Then I open that connection: con.Open(); and I also created the…
Dzeko
  • 27
  • 6
-3
votes
2 answers

How can I set the time out, in the command and the connection?

this is my code in the dataset.cs. what do I have to add for set the timeout in the connection and the command? namespace M_Report { partial class A_DBDataSet { partial class VP_DataTable { } } } namespace…
user11116003
-3
votes
2 answers

update query not working c#

I have used this query in sql management studio and it works, I have tried a shortened query without the and condition and it works, why is the and condition breaking the code? string dbQuery = "update log_file set updated = @true where urn = @urn…
Jed I
  • 998
  • 3
  • 19
  • 37
-4
votes
0 answers

Executing SQLCommand gets increasingly slower each time it's run

Why does this run in about 7 seconds for a the first few times I run it and then get increasingly slower after that? using (SqlConnection con = new SqlConnection(connectionStr)) { con.Open(); using (SqlCommand…
davy
  • 4,474
  • 10
  • 48
  • 71
-4
votes
3 answers

Error during SQL Update: "Incorrect Syntax Near '1'"

I have an application that I'm trying to use to make some database updates. However, whenever I try to save, I get this error message: Incorrect Syntax Near '1' What does this error message mean, and how can I solve it? Here's my code: try { …
-4
votes
2 answers

SQL change word command

How to change the location of the letters 5 and 6 in sql. For example: word:weather new word:weatehr
user8419319
1 2 3
61
62