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

SQL 'ONCREATE' command

I am using DeZign for Databased v6 to design my sql database. It has worked perfectly, up until this current view SQL code: CREATE VIEW %viewname% AS SELECT dbo.tblSiteChallengeMember.id, tblSiteMemberDetail_2.memberNickname AS mediator,…
TheGeekZn
  • 3,696
  • 10
  • 55
  • 91
0
votes
1 answer

sql syntax error in vb.net

I've the following vb.net function which have a syntax error in the sql commandtext that i can't seem to figure out Private Sub addsupporderidsinbookedtoinprocess() Try Dim cnn3 As New SqlConnection(connetionString) …
user1570048
  • 880
  • 6
  • 35
  • 69
0
votes
1 answer

Perform an update on a SQL table based on passed parameter

This program was already written and I need to add to it an update SQL statement to update another table based on @IN. After declaring the SQL command how do I get it to excute, can I use the same SQLConnection as other sql command? WHat this…
LewSim
  • 307
  • 2
  • 9
  • 24
0
votes
1 answer

Entity Framework, SqlCommand and TransactionScope

I have a repository done in EF 4.3 Code First (EF) , and another repository that uses regular SqlCommand (SQLCMD). EF pass the connection object to SQLCMD, so both are using the same connection. In EF I create an entity, and use the entity Id to do…
0
votes
1 answer

WPF App run SQL Server Scripts

I often have to 'Generate Scripts' for stored procedures on SQL Server Management Studio. I need to create a WPF app that will take the file produced and execute it. I know you can do this: SqlCommand insert = new SqlCommand(sql,…
user1166905
  • 2,612
  • 7
  • 43
  • 75
0
votes
1 answer

Insert not working

I've searched evreywhere and tried all suggestions but still no luck when running the following code. Note that some code is commented out. Thats just me trying different things. SqlConnection connection = new SqlConnection("Data…
0
votes
2 answers

Error when inserting multiple rows in SQL table

I am trying to insert multiple records into SQL database. SQL table contains smalldatetime column. Every record is for one hour period, so when you want to insert timespan for, eg. 5 hours, you fill in 5 records into database. Code looks something…
miller
  • 1,636
  • 3
  • 26
  • 55
0
votes
1 answer

SQL Remote Connection with file read

So I am trying to access my servers databse reomtely and have it run commands to export several tables all to individual csv files. So what I have is a commmand line command parameters that look like this: mysql -h 198.xxx.xxx.xxx -u user-p <…
D3TXER
  • 152
  • 2
  • 13
0
votes
2 answers

Extract the SQL Command from a database VB 2010

This may be a very strange question but I am trying to 'obtain' the SQL command for the purpose of reporting. So say my Microsoft Access Database has a query which when executed, runs this SQL statement: SELECT Staff.SurName, Staff.ID, Staff.Salary,…
AdamWest
  • 29
  • 1
  • 9
0
votes
2 answers

Multiple or single 'using' statements?

I was wondering if the below way of handling multiple sql's within the same using statement is correct, I have tested this in a project and it works but would it not be better to wrap each sql in it's own using statement? Which option is a better…
03Usr
  • 3,335
  • 6
  • 37
  • 63
0
votes
2 answers

sqlCommand object and adding parameters using loop

We can clear all the text boxes in a form using foreach without typing codes for each text box to clear them. com.Parameters.Add(new SqlParameter("@",objPlayrInjr_P)); using (SqlCommand com = new SqlCommand()) { com.CommandText = "SPname"; …
Sameera
  • 373
  • 2
  • 4
  • 16
0
votes
1 answer

Last inserted record not displaying in listview until I close and re-run the app

This is my first post in this type of forum so please forgive my ignorance. I have a WPF application with a SQL Server 2008 mdf database. I use the following code to insert a new record into a table called Sales_TBL. SqlConnection con = new…
0
votes
4 answers

Executing multiple statements / sqlcomands within a single ado.net transaction

I'm not including any code here because I've re-written it so many times over the past few days its really not worth bothering with any more, so I'll explain my problem in generic terms. I have a winforms application written in C# and connected to a…
PJW
  • 5,197
  • 19
  • 60
  • 74
0
votes
1 answer

A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll in vb.NET

I'm new in Visual Studio and as well as SQL Server. I got confused on how to insert data from visual studio application I got an error of System.InvalidCastException. I am confused of what is the problem. This is my…
Mineko
  • 641
  • 2
  • 14
  • 21
0
votes
1 answer

How to save data to the sql database using SqlCommand

I'm new in Visual Studio and as well as SQL Server. I got confused on how to insert data from visual studio application This is my code: Try '===============Add New Patient=================== patient_name = txtName.Text patient_age =…
Mineko
  • 641
  • 2
  • 14
  • 21